javascript - Bundle multiple files with gulp and browserify -
i have project structure that:
src |html |javascript |file_one.js |file_two.js |styles dist gulpfile.js
my question is: how can bundle files within "javascript" folder root "dist" folder renaming bundle files in following way?
file_one.js ----> file_one.bundle.js file_two.js ----> file_two.bundle.js
i'm doing following, can't put bundle files root "dist" folder, and, don't know if pretty way.
gulp.task("bundler", function(){ var src_arr = ['src/javascript/file_one.js', 'src/javascript/file_two.js']; src_arr.foreach(function(file) { var bundle = browserify([file]).bundle(); bundle.pipe(source(file.substring(0,file.indexof('.')) + ".bundle.js")) .pipe(gulp.dest('dist/')); }); });
any appreciated. thanks
i guess more long comment "answer"…
various ways deal multiple browserify entry points covered in browserify - multiple entry points , in @hafiz ismail's https://wehavefaces.net/gulp-browserify-the-gulp-y-way-bb359b3f9623.
since you're dealing 2 know files rather glob, gulpiest solution might set browserifying lazypipe (https://github.com/overzealous/lazypipe), , call 2 separate tasks - 1 be
gulp.task('first', function(){ gulp.src('src/javascript/file_one.js') .pipe(browserifyinglazypipe()) };
(i freely admit haven't tried using browserify in lazypipe)
a gulpy way renaming use gulp-rename
.pipe(rename({ extname: '.bundle.js' })
Comments
Post a Comment