Continuously concatenates files (makes gulp-watch useful again for concated files)
|Description||Continuously concatenates files|
|Node Version||>= 0.4|
var watch = require'gulp-watch';var concat = require'gulp-continuous-concat';gulptask'scripts'gulpsrc'./lib/*.js'pipewatchglob: './lib/*.js'pipeconcat'all.js'pipegulpdest'./dist/';
This will continously concat files by your operating systems newLine. This differs from the standard
gulp-concat plugin in that it does not require previous streams to emit an
end to work. The typical use case for this plugin is after using
gulp-watch, which does not emit an
end. This prevents normal
gulp-concat from ever finishing. Using the above example with standard
gulp-concat, the concatenated file would never be created:
var watch = require'gulp-watch';var concat = require'gulp-concat'; // <-- standard gulp-concatgulptask'scripts'gulpsrc'./lib/*.js'pipewatchglob: './lib/*.js' // <-- will never emit 'end'pipeconcat'all.js' // <-- sits around forever, waiting for 'end'pipegulpdest'./dist/';
gulp-continuous-concat gets around this by rebuilding the destination file on every incoming file. To avoid excessive rebuilding (for example, when first running the command on several files), it debounces the build step so it will only run after 100ms of not being called (the debouncing period is configurable via the
debounce option on the options hash).
Files will be concatenated in the order that they are supplied, and will maintain that order even if one of those files is later re-emitted from upstream. For example, to concat
./lib/file2.js in that order, the following code would create a task to do that:
var concat = require'gulp-continuous-concat';gulptask'scripts'gulpsrc'./lib/file3.js' './lib/file1.js' './lib/file2.js' // <-- emits the files in orderpipewatch // <-- later, ./lib/file1.js changes and re-emitted from herepipeconcat'all.js' // <-- continuous-concat maintains the original gulp.src orderpipegulpdest'./dist/';
gulp-watch does not emit files that were deleted, if you add a continuous concat step after a
gulp-watch, and then delete a file, it will not be removed from the concatentated result.
If and when
gulp-watch adds this functionality, this plugin could be updated to remove deleted files from the result.
Apache 2.0 (See LICENSE file for full details)