Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to minify gulp-webpack file?

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.

like image 351
Sergey_Ksenofontov Avatar asked May 26 '15 15:05

Sergey_Ksenofontov


1 Answers

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'));
});
like image 195
Sergey_Ksenofontov Avatar answered Oct 14 '22 01:10

Sergey_Ksenofontov