Concatenate files with gobble.
First, you need to have gobble installed - see the gobble readme for details. Then,
npm i -D gobble-concat
gobblefile.js
var gobble = require( 'gobble' );
module.exports = gobble( 'js' ).transform( 'concat', { dest: 'bundle.js' });
The dest
property is required. Other values - files
, sort
, separator
and writeSourcemap
, explained below - are optional.
You can specify which files are included, and their order, like so:
var gobble = require( 'gobble' );
module.exports = gobble( 'js' )
.transform( 'concat', {
dest: 'bundle.js',
files: [ 'foo.js', 'bar.js', 'baz.js' ]
});
The files
option can be a minimatch pattern:
var gobble = require( 'gobble' );
module.exports = gobble( 'js' )
.transform( 'concat', {
dest: 'bundle.js',
files: [ 'vendor/**/*.js', 'src/**/*.js' ]
});
Within each pattern, if multiple files are found, they will be sorted alphabetically by default. You can override this by passing a sort
option, which is a standard compare function].
If files match multiple patterns, they will only be included once (upon the first match).
By default, files will be separated by newlines. You can change this to be any string:
var gobble = require( 'gobble' );
module.exports = gobble( 'js' )
.transform( 'concat', {
dest: 'bundle.js',
separator: '/* YOLO */'
});
Concatenating javascript or CSS files requires some extra handling of their sourcemaps, specially in complex workflows. With this option set to true
, the sourcemaps of the files to be concatenated will be parsed, files with no sourcemap will be assigned an identity (1:1) sourcemap, and a new sourcemap will be generated from all of them.
The default value is true
when dest
is a file with a .js
or .css
extension, and false
otherwise.
MIT. Copyright 2014 Rich Harris
"THE BEER-WARE LICENSE": [email protected] wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.