Skip to content

Commit 16a85c1

Browse files
authored
Merge pull request #1 from Geta/feature/switch-to-terser
Use terser instead of uglify for JS optimization
2 parents 8428616 + 7dbfa51 commit 16a85c1

File tree

4 files changed

+315
-52
lines changed

4 files changed

+315
-52
lines changed

docs/webpack.core.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Allows you to override the default target of the config. Default target is ```we
135135

136136
#### About
137137

138-
Adds generic optimizations for production. Currently contains the ```uglifyjs-webpack-plugin``` and ```optimize-css-assets-webpack-plugin```.
138+
Adds generic optimizations for production. Currently contains the ```terser-webpack-plugin``` and ```optimize-css-assets-webpack-plugin```.
139139

140140
### .addSourceMapsForDevelopment()
141141

@@ -184,4 +184,4 @@ Adds TypeScript and TSLint support to the project. If mode is production, linter
184184

185185
Formats the config into a object and returns it. The object is formatted following the webpack best practices. Enables watchmode if mode is development.
186186

187-
After the config is returned, it is possible to manually adjust the object in your config, if there are some use case which is not covered in this helper.
187+
After the config is returned, it is possible to manually adjust the object in your config, if there are some use case which is not covered in this helper.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@
7272
"stylelint-config-standard": "^19.0.0",
7373
"stylelint-scss": "^3.12.0",
7474
"stylelint-webpack-plugin": "^1.0.3",
75+
"terser-webpack-plugin": "^2.2.1",
7576
"ts-loader": "^5.2.1",
7677
"tsconfig-paths-webpack-plugin": "^3.2.0",
7778
"typescript": "^3.6.4",
78-
"uglifyjs-webpack-plugin": "^2.0.1",
7979
"url-loader": "^2.2.0",
8080
"webpack": "^4.41.2",
8181
"webpack-bundle-analyzer": "^3.6.0",

proto/with-optimizations.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const modes = require('../constants/modes');
2-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
32
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
3+
const TerserPlugin = require('terser-webpack-plugin');
44

55
module.exports = function(context, mode) {
6-
if (mode === modes.production) {
7-
context._optimization['minimizer'] = [
8-
new UglifyJsPlugin({
9-
cache: true,
10-
parallel: true,
11-
sourceMap: false,
12-
}),
13-
new OptimizeCssAssetsPlugin({}),
14-
];
6+
const isProduction = mode === modes.production;
7+
const minimizerPlugins = [new TerserPlugin()];
8+
9+
if (isProduction) {
10+
minimizerPlugins.push(new OptimizeCssAssetsPlugin({}))
1511
}
12+
13+
context._optimization['minimize'] = mode === modes.production;
14+
context._optimization['minimizer'] = minimizerPlugins;
15+
1616
return this;
1717
};

0 commit comments

Comments
 (0)