我正在使用gulp将browserify + babelify与uglifyjs捆绑在一起。 Ø 但是,从我的项目生成的源图只给了我捆绑的版本,而不是捆绑的版本。
这是我的设置:
var gulp = require('gulp'),
source = require('vinyl-source-stream'),
browserify = require('browserify'),
gutil = require('gulp-util'),
buffer = require('vinyl-buffer'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
file = 'index.js';
gulp.task('build', function(){
return browserify({
entries: [file],
transform: ["babelify"]
})
.bundle()
.pipe(source(file))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/js'))
.pipe(gutil.noop())
})
有没有办法让我创建一个捆绑babel => browserify => uglify并仍然将地图返回给我的pre-babel文件的构建?
我也不介意不使用gulp(我实际上更喜欢咕噜声,但过去这种设置过去对我有用)。
答案 0 :(得分:9)
首先,您需要设置browserify以通过将debug选项设置为true来生成源映射,然后如果您需要pre babelify源映射,则需要配置babelify以生成源映射:
var gulp = require('gulp'),
source = require('vinyl-source-stream'),
browserify = require('browserify'),
gutil = require('gulp-util'),
buffer = require('vinyl-buffer'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify'),
babelify = require('babelify')
file = 'index.js';
gulp.task('build', function(){
return browserify(file,{debug:true}).transform(babelify, {presets: ["es2015", "react"],sourceMaps:true})
.bundle()
.pipe(source(file))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./build/js'))
.pipe(gutil.noop())
})