Посмотри мой gulpfile, может быть поможет
'use strict';
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const uglify = require('gulp-uglify');
const useref = require('gulp-useref');
const rename = require('gulp-rename');
const browserify = require('browserify');
const babelify = require('babelify');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
const sourcemaps = require('gulp-sourcemaps');
// use default task to launch Browsersync and watch JS files
gulp.task('serve', ['js'], () => {
// Serve files from the root of this project
browserSync.init({
proxy: "localhost"
});
// add browserSync.reload to the tasks array to make
// all browsers reload after tasks are complete.
gulp.watch("src/*.js", ['js']);
gulp.watch("*.html").on("change", browserSync.reload);
gulp.watch("dist/*.js").on("change", browserSync.reload);
gulp.watch("ssi/*.shtml").on("change", browserSync.reload);
gulp.watch("css/*.css").on("change", browserSync.reload);
});
// process JS files and return the stream.
gulp.task('js', () => {
let bundler = browserify({
entries: 'src/main.js',
debug: true
});
bundler
.transform(babelify, {
presets: ['es2015'],
compact: false,
ignore: /libs/
})
.transform('browserify-shim');
bundler.bundle()
.on('error', err => console.error(err))
.pipe(source('main.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist'))
.pipe(browserSync.stream());
});
// create a task that ensures the `js` task is complete before
// reloading browsers
gulp.task('default', ['serve']);