如何缩小 gulp-webpack 文件?
How to minify gulp-webpack file?
有如下情况:
gulp.task('webpack', function(cb) {
gulp.src('webpack-init.js')
.pipe(webpack({
output: {
filename: 'bundle.js',
},
}))
.pipe(gulp.dest('./client/js'));
cb();
});
没问题,但我想缩小输出文件。
如果我直接使用gulp-uglify -
.pipe(webpack(...))
.pipe(uglify().on('error', gutil.log))
.pipe(gulp.dest('./client/js'));
有一个错误:"Unexpected token: punc ())]" 和其他类似的错误。
我找到了解决办法。我们可以使用普通版本的 webpack(不仅仅是 gulp-webpack)来提供插件包含能力:
var gulpWebpack = require('gulp-webpack'),
webpack = require('webpack');
gulp.task('webpack', function() {
gulp.src('webpack-init.js')
.pipe(gulpWebpack({
output: {
filename: 'bundle.js',
},
plugins: [new webpack.optimize.UglifyJsPlugin()],
}, webpack))
.pipe(gulp.dest('./client/js'));
});
有如下情况:
gulp.task('webpack', function(cb) {
gulp.src('webpack-init.js')
.pipe(webpack({
output: {
filename: 'bundle.js',
},
}))
.pipe(gulp.dest('./client/js'));
cb();
});
没问题,但我想缩小输出文件。
如果我直接使用gulp-uglify -
.pipe(webpack(...))
.pipe(uglify().on('error', gutil.log))
.pipe(gulp.dest('./client/js'));
有一个错误:"Unexpected token: punc ())]" 和其他类似的错误。
我找到了解决办法。我们可以使用普通版本的 webpack(不仅仅是 gulp-webpack)来提供插件包含能力:
var gulpWebpack = require('gulp-webpack'),
webpack = require('webpack');
gulp.task('webpack', function() {
gulp.src('webpack-init.js')
.pipe(gulpWebpack({
output: {
filename: 'bundle.js',
},
plugins: [new webpack.optimize.UglifyJsPlugin()],
}, webpack))
.pipe(gulp.dest('./client/js'));
});