Bundle CommonJS scripts through vinyl stream, using browserify.
npm install bundle-through
const bundler = require('bundle-through')
const gulp = require('gulp')
gulp.src('src/js/pages/*.js')
.pipe(bundler())
.pipe(gulp.dest('dist/'))
This bundles all CommonJS scripts (require
/ module.exports
) through the stream. Each entry in the stream is considered as the only entrypoint of the bundle.
bundle-through
takes arguments and they are passed to browserify. For example, you can pass transform
option to add the transforms.
gulp.src('src/js/pages/*.js')
.pipe(bundler({transform: 'babelify'}))
.pipe(gulp.dest('dist/'))
Set sourcemaps
option true
and write sourcemaps using gulp-sourcemaps
.
const sourcemaps = require('gulp-sourcemaps')
gulp.src('src/js/pages/*.js')
.pipe(bundler({sourcemaps: true}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/'))
const bundler = require('bundle-through')
- @param {boolean} buffer
true
iff you want output file to have buffer type contents. Default istrue
. If setfalse
, the output file has file contents as a stream. - @param {boolean} sourcemaps
true
iff you want to output sourcemaps. You need to write it usinggulp-sourcemaps
. - These options are directly passed to
browserify
. See the documents for details. - @return {Transform<Vinyl, Vinyl>}
This returns Transform stream of the object mode which transform CommonJS scripts into the bundle using browserify. Each entry in the stream is considered as the only entrypoint of the bundle and therefore input and output files has the 1-to-1 relationship.
MIT