Skip to content

Commit 95e2e71

Browse files
committed
fix: uglifyJs merge with object and array mode
1 parent c2a5831 commit 95e2e71

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

lib/core/config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ class Config {
103103
return this.utils.normalizePublicPath(publicPath);
104104
}
105105

106+
get devtool() {
107+
return this.webpackConfig.devtool;
108+
}
109+
106110
get host() {
107111
let host = '';
108112
const config = this.config;

lib/core/optimize.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,30 @@ module.exports = class WebpackOptimize {
6565
delete this.optimization.minimizer;
6666
}
6767
// compatible old config
68-
const { plugins = {} } = this.ctx.config;
69-
if (this.ctx.prod && !this.optimization.minimizer && this.ctx.utils.isObject(plugins.uglifyJs)) {
70-
const args = plugins.uglifyJs.args || plugins.uglifyJs;
71-
const options = this.ctx.merge({
72-
cache: true,
73-
parallel: 2,
74-
sourceMap: false,
75-
uglifyOptions: {
76-
warnings: false,
77-
compress: {
78-
dead_code: true,
79-
drop_console: true,
80-
drop_debugger: true
81-
},
82-
output: {
83-
comments: false
68+
if (this.ctx.prod && !this.optimization.minimizer) {
69+
const uglifyJs = this.ctx.getConfigPlugin('uglifyJs');
70+
if (uglifyJs) {
71+
const args = this.ctx.utils.isObject(uglifyJs) ? uglifyJs.args || uglifyJs : {};
72+
const options = this.ctx.merge({
73+
cache: true,
74+
parallel: 4,
75+
sourceMap: !!this.ctx.devtool,
76+
uglifyOptions: {
77+
ie8: false,
78+
warnings: false,
79+
compress: {
80+
dead_code: true,
81+
drop_console: true,
82+
drop_debugger: true
83+
},
84+
output: {
85+
comments: false
86+
}
8487
}
85-
}
86-
}, args);
87-
this.optimization.minimizer = [ new UglifyJsPlugin(options) ];
88+
}, args);
89+
this.optimization.minimize = false;
90+
this.optimization.minimizer = [ new UglifyJsPlugin(options) ];
91+
}
8892
}
8993
return this.optimization;
9094
}

lib/core/plugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ module.exports = {
66
getConfigPlugin(label) {
77
const plugins = this.config.plugins || {};
88
if (Array.isArray(plugins)) {
9-
return plugins.find(plugin => {
10-
return plugin[label] || {};
9+
const plugin = plugins.find(item => {
10+
return item.hasOwnProperty(label);
1111
});
12+
return plugin && plugin[label] || {};
1213
}
1314
return plugins[label] || {};
1415
},

0 commit comments

Comments
 (0)