I use gulp to run Webpack, with webpack-stream.
I use this config and works will with me.
How can I run Webpack production-build webpack -p from gulp?
I use gulp to run Webpack, with webpack-stream.
I use this config and works will with me.
How can I run Webpack production-build webpack -p from gulp?
Webpack 4 supports specifying mode: "production"
in the config object.
Here's the config (shamelessly borrowing from Sven's answer):
var gulp = require('gulp');
var webpackStream = require('webpack-stream');
var webpack4 = require('webpack'); // Assuming we've installed Webpack 4+
gulp.task('default', function() {
var options = {
mode: "production"
};
return gulp.src('src/entry.js')
.pipe(webpackStream(options, webpack4))
.pipe(gulp.dest('dist/'));
});
According to the webpack documentation using webpack -p
is equivalent to the following:
webpack --optimize-minimize --define process.env.NODE_ENV="'production'"
Those two options add the webpack.optimize.UglifyJsPlugin
and the webpack.DefinePlugin
respectively.
What you need to do is to manually add those two plugins in your webpack configuration.
Based on the other answer that you linked to that should look like this:
var gulp = require('gulp');
var webpackStream = require('webpack-stream');
var webpack2 = require('webpack');
gulp.task('default', function() {
var options = {
plugins: [
new webpack2.DefinePlugin({
'process.env': { 'NODE_ENV': "'production'" }
}),
new webpack2.optimize.UglifyJsPlugin()
]
};
return gulp.src('src/entry.js')
.pipe(webpackStream(options, webpack2))
.pipe(gulp.dest('dist/'));
});