Gulp plugin that runs a local server that executes tasks when a page is requested, not when the file changes
Runs a local server that executes tasks when a page is requested, not when the files change
It will keep track of the file changes; but instead of running the tasks directly it will run them all at once when a request arrives, before it hits the real development server.
Install via npm:
npm install gulp-ondemand-server --save-dev
var gulp = require'gulp'OnDemandServer = require'gulp-ondemand-server';gulptask'default'var server = ;// You can register a pattern of files to watch and the task to execute// when they change and a request arrive.serverwatch'**/*.js' 'lint';// You can watch arrays of patterns, and execute arrays of tasks.serverwatch'styles/*.scss' 'styles/*.sass' 'sass' 'autoprefixer';// You should register the host you need, as well as the target URL// they're proxying.// For example to proxy everything from localhost:9810 ---> localhost:80serverregisterHost'localhost' '';// You can have several hosts registered, as long as they share the proxy port// This will proxy ---> foo:80serverregisterHost'mydomain.localhost' '';// Another example: example-local:9810 ---> localhost:7653serverregisterHost'example-local' '';// Start listening in this portserverstart9810;;
NOTE: If you want custom local domains in Linux, you can edit /etc/hosts and copy-paste the localhost line with the new domain.
globs- array of globs of files to watch for changes.
tasks- array of tasks to run when a requests arrive and the files have changed.
Both globs and tasks can be a single string too.
host- the host we're registering
proxyUrl- the target URL for the proxy; protocol, host and port only. E.g.:
You should register all hosts you want to use before starting the server (calling this function as much as needed).
port- the port we'll listen to
All registered hosts will share this port.
Mainly because I have a not-so-good laptop that doesn't keep up compiling every time I change the Sublime tab (and autosaves).
With this plugin I can develop and save as much as I want, and it will execute only the needed tasks before any request hits the real page (when I refresh the page).