Have a follow situation:
gulp.task('webpack', function(cb) {
  gulp.src('webpack-init.js')
    .pipe(webpack({
      output: {
        filename: 'bundle.js',
      },
    }))
    .pipe(gulp.dest('./client/js'));
  cb();
});
All ok, but i want to minify output file.
If i use gulp-uglify directly -
.pipe(webpack(...))
.pipe(uglify().on('error', gutil.log))
.pipe(gulp.dest('./client/js'));
have an error: "Unexpected token: punc ())]" and others of that ilk.
I found a solution. We can use normal version of webpack (not just gulp-webpack) to provide plugin include capability:
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'));
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With