You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: webpack.optimize.UglifyJsPlugin is not a constructor #6409
Any docs available for config.optimization.minimize? Google brings up zero results.
Also it'd be nice to include a friendly message about this in webpack itself because plenty of people will be hitting that error.
Reacted by Fernando Montoya, Elvin Qi, Jesal Gadhia, Brian Andress, CASSIN Kémy, Mark Bjerke, Darren Barklie, Frank M, Ryan Sullivan, Yasir Janjua and 31 more
When mode is production or not defined, minimize is enabled. This option automatically adds Uglify plugin. If you want to add your own setup, you should set minimize to false to avoid double minification.
Because minimize tells webpack to use optimization.minimizer to create the minification plugin. Currently it creates uglify’s one but one could set it to closure or babili.
@ooflorent If my configuration is in another package, @evilebottnawi variant is more convenient. There is no need to add uglifyjs-webpack-plugin in dependencies.
Hi guys, Sorry for coming back to this topic, but I have tried a billion ways now to get the UglyJsPlugin running. All I get i the same error over and over again. Any thoughts what I might be doing wrong here?
@D19cannon seriously? You use const UglifyJsPlugin = require('uglifyjs-webpack-plugin') in top, but in minimizer option you use UglifyJSPlugin. Look on s in plugin name (first example with lowercase, second in UPPERCASE)
My bad. I copied that part from an example from somewhere. Also, when i searched for it VScode didn't distinct the uppercase from the lowercase, but instead recognises the words as its whole.
Thank you :)
Reacted by Dan Christian, Nelson Eldoro, pwcueblocks and tomtheisen
Activity
michael-ciniawsky commentedon Jan 29, 2018
CommonChunksPlugin(removed) &&UglifyJsPluginaren't exposed as plugins anymore since[email protected], useconfig.optimization.splitChunks && config.optimization.minimizeinstead pleasefregante commentedon Jan 29, 2018
Any docs available for
config.optimization.minimize? Google brings up zero results.Also it'd be nice to include a friendly message about this in webpack itself because plenty of people will be hitting that error.
swarajgiri commentedon Jan 30, 2018
@bfred-it - https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
fregante commentedon Jan 30, 2018
Thanks! Is it possible to configure the minification as well?
ooflorent commentedon Jan 30, 2018
@bfred-it yes. Set
optimization.minimizetofalse, adduglifyjs-webpack-pluginto your project deps. Use this one instead of webpack’s builtin.NekR commentedon Jan 30, 2018
Now it's even more confusing. What exactly minimize option is doing then?
ooflorent commentedon Jan 30, 2018
When
modeisproductionor not defined,minimizeis enabled. This option automatically adds Uglify plugin. If you want to add your own setup, you should setminimizetofalseto avoid double minification.NekR commentedon Jan 30, 2018
fregante commentedon Jan 30, 2018
If you set
minimize: falseyou won’t have double minification.What I don’t understand is why not make
minimizeaccept auglifyjs-webpack-pluginconfig object.ooflorent commentedon Jan 30, 2018
Because
minimizetells webpack to useoptimization.minimizerto create the minification plugin. Currently it creates uglify’s one but one could set it to closure or babili.ooflorent commentedon Jan 30, 2018
But sure, minimize could also accept an object and pass it to minimizer. What do you think about this @sokra?
alexander-akait commentedon Jan 30, 2018
@ooflorent should accept, otherwise, how to configure uglify plugin?
benthemonkey commentedon Jan 30, 2018
I could be mistaken, but if you look at https://github.com/webpack/webpack/blob/next/lib/WebpackOptionsApply.js#L306, you'll see that if
optimization.minimize = true, then webpack just takes the array of plugins fromoptimization.minimizer(e.g.optimization.minimizer = [new UglifyJSPlugin(your options)]) and applies it to the compiler. So I think that's how you should configure the uglify plugin.backflip commentedon Feb 7, 2018
@benthemonkey, there seem to be issues with the config validation when doing this. Example:
This triggers the following error for me:
UPDATE: Never mind, happens as well for
alexander-akait commentedon Feb 7, 2018
@backflip ?
backflip commentedon Feb 7, 2018
I was using an outdated structure, the config needs to be wrapped with
uglifyOptions:Sorry for spamming.
Vnthf commentedon Feb 26, 2018
@backflip But treeshaking not work anymore if I use minimizer option. I think unused option not work in webpack4. right?
ooflorent commentedon Apr 4, 2018
webpack.optimize.UglifyJsPluginis gone in webpack 4.Now you must load the plugin:
And register it:
grig0ry commentedon Apr 13, 2018
@ooflorent If my configuration is in another package, @evilebottnawi variant is more convenient. There is no need to add uglifyjs-webpack-plugin in dependencies.
D19cannon commentedon Jul 23, 2018
Hi guys, Sorry for coming back to this topic, but I have tried a billion ways now to get the UglyJsPlugin running. All I get i the same error over and over again. Any thoughts what I might be doing wrong here?
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
module.exports = {
mode: "production",
optimization: {
minimizer: [
new UglifyJSPlugin({
sourceMap: true,
ecma: 5,
warnings: false,
ie8: false,
safari10: false,
dead_code: true,
comments: false,
uglifyOptions: {
compress: {
inline: false
}
}
})
]
},
...
};
alexander-akait commentedon Jul 23, 2018
@D19cannon what error you are got?
D19cannon commentedon Jul 23, 2018
@evilebottnawi ReferenceError: UglifyJSPlugin is not defined
Error doesn't make any sense to me. As you can see I have the require() and with an extension in VScode I can see that 733.3k has been imported.
Any ideas?
alexander-akait commentedon Jul 23, 2018
You need add
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')in your config fileD19cannon commentedon Jul 23, 2018
@evilebottnawi Yes I understand, but as I mentioned in my first message. It is there, but I still receive this error.
D19cannon commentedon Jul 23, 2018
alexander-akait commentedon Jul 23, 2018
@D19cannon seriously? You use
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')in top, but inminimizeroption you useUglifyJSPlugin. Look onsin plugin name (first example with lowercase, second in UPPERCASE)D19cannon commentedon Jul 23, 2018
My bad. I copied that part from an example from somewhere. Also, when i searched for it VScode didn't distinct the uppercase from the lowercase, but instead recognises the words as its whole.
Thank you :)
danchristian commentedon Aug 9, 2018
Tripped up on this too, thanks!
phoeson commentedon Jan 14, 2019
And first of all, you need to install the package
npm install uglifyjs-webpack-plugin --save-dev