How to minimize gulp -webpack file?

You have the following situation:

gulp.task('webpack', function(cb) { gulp.src('webpack-init.js') .pipe(webpack({ output: { filename: 'bundle.js', }, })) .pipe(gulp.dest('./client/js')); cb(); }); 

Everything is fine, but I want to minimize the output file.

If I use gulp -uglify directly -

 .pipe(webpack(...)) .pipe(uglify().on('error', gutil.log)) .pipe(gulp.dest('./client/js')); 

have the error: "Unexpected token: punc ())]" and others from this file.

+7
javascript webpack compression gulp
source share
1 answer

I have found a solution. We can use the regular version of webpack (and not just gulp -webpack) to enable the plugin:

 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')); }); 
+9
source share

All Articles