Webpack 4 comes with the following statement:
Error:
webpack.optimize.UglifyJsPluginhas been removed, please useconfig.optimization.minimizeinstead.
Fair enough, but I cannot find any information about configuring the UglifyJsPlugin instance running under the hood, for example to change the cache directory. Can this be done?
It's not possible to modify the default configuration.
You can use the optimization.minimizer setting to instantiate your own UglifyJsPlugin, however. Using 4.0 we used this example to get source maps even when mode is set to 'production' for example (no longer necessary as of 4.1.1):
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
optimization: {
minimizer: [
// we specify a custom UglifyJsPlugin here to get source maps in production
new UglifyJsPlugin({
cache: true,
parallel: true,
uglifyOptions: {
compress: false,
ecma: 6,
mangle: true
},
sourceMap: true
})
]
}
};
Without adding uglifyjs-webpack-plugin, you can just add this to the end of your webpack.prod.config.js file:
optimization: {
minimize: false
}
You can try this
npm install uglifyjs-webpack-plugin --save-dev
webpack.config.js
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
optimization: {
minimizer: [new UglifyJsPlugin()],
},
};