I found a solution, by crawling the web, and it looks like this:
var browserify = require('browserify');
var gulp = require('gulp');
var exorcist = require('exorcist');
var source = require('vinyl-source-stream');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps'); // https://www.npmjs.org/package/gulp-sourcemaps
gulp.task('browserify', function(){
return browserify({
entries: ['./file1.js'],
debug: true
})
.bundle()
.pipe(exorcist('./output.js.map'))
.pipe(source('output.js'))
.pipe(gulp.dest('./'));
});
gulp.task('together', ['browserify'], function() {
return gulp.src('output.js')
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(concat('all-with-maps.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.', {addComment: true /* the default */, sourceRoot: '/src'}))
.pipe(gulp.dest('dist'));
});
Make sure you have a recent version of browserify installed (I use 5.10.0 as of today).. You used to need to pass {debug: true}
to the bundle()
call .. but it has moved to browserify()
directly.
Regarding the blacklisting: it is thought to be better to use browserify()
directly, as we do here. There's no need for a plugin it would seem.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…