Skip to content

Commit 49cfeba

Browse files
peterblazejewiczMarkPieszak
authored andcommitted
feat(webpack): migrate to terser from uglifiy
This fixes webpack build in production mode See @webpack/webpack#7908 Thanks!
1 parent 57273e1 commit 49cfeba

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ import * as $ from 'jquery';
427427
428428
### How can I support IE9 through IE11?
429429
430-
To support IE9 through IE11 open the `polyfills.ts` file in the `polyfills` folder and uncomment out the 'import polyfills' as needed. ALSO - make sure that your `webpack.config` and `webpack.config.vendor` change option of `UglifyJsPlugin` from `ecma: 6` to **`ecma: 5`**.
430+
To support IE9 through IE11 open the `polyfills.ts` file in the `polyfills` folder and uncomment out the 'import polyfills' as needed. ALSO - make sure that your `webpack.config` and `webpack.config.vendor` change option of `TerserPlugin` from `ecma: 6` to **`ecma: 5`**.
431431
432432
----
433433

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"karma-sourcemap-loader": "^0.3.7",
9090
"karma-webpack": "^3.0.5",
9191
"mini-css-extract-plugin": "^0.5.0",
92+
"terser-webpack-plugin": "^1.2.1",
9293
"tslint": "^5.12.0",
9394
"typescript": "^3.1.3",
9495
"uglifyjs-webpack-plugin": "^2.1.1",

webpack.config.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const AngularCompilerPlugin = require('@ngtools/webpack').AngularCompilerPlugin;
1515
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
1616
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
1717
.BundleAnalyzerPlugin;
18-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
18+
const TerserPlugin = require('terser-webpack-plugin');
1919

2020
const { sharedModuleRules } = require('./webpack.additions');
2121

@@ -118,19 +118,17 @@ module.exports = env => {
118118
isDevBuild
119119
? []
120120
: [
121-
// we specify a custom UglifyJsPlugin here to get source maps in production
122-
new UglifyJsPlugin({
123-
cache: true,
124-
parallel: true,
125-
uglifyOptions: {
126-
compress: false,
121+
// we specify a custom TerserPlugin here to get source maps in production
122+
new TerserPlugin({
123+
sourceMap: true,
124+
terserOptions: {
125+
compress: true,
127126
ecma: 6,
128127
mangle: true,
129128
keep_classnames: true,
130-
keep_fnames: true
129+
keep_fnames: true,
131130
},
132-
sourceMap: true
133-
})
131+
}),
134132
]
135133
)
136134
}
@@ -196,18 +194,18 @@ module.exports = env => {
196194
isDevBuild
197195
? []
198196
: [
199-
// we specify a custom UglifyJsPlugin here to get source maps in production
200-
new UglifyJsPlugin({
197+
// we specify a custom TerserPlugin here to get source maps in production
198+
new TerserPlugin({
201199
cache: true,
202200
parallel: true,
203-
uglifyOptions: {
201+
sourceMap: true,
202+
terserOptions: {
204203
compress: false,
205204
ecma: 6,
206205
mangle: true,
207206
keep_classnames: true,
208-
keep_fnames: true
207+
keep_fnames: true,
209208
},
210-
sourceMap: true
211209
})
212210
]
213211
)

webpack.config.vendor.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require('path');
22
const webpack = require('webpack');
33
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
44
const merge = require('webpack-merge');
5-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
5+
const TerserPlugin = require('terser-webpack-plugin');
66
const treeShakableModules = [
77
'@angular/animations',
88
'@angular/common',
@@ -95,18 +95,18 @@ module.exports = (env) => {
9595
]),
9696
optimization: {
9797
minimizer: [].concat(isDevBuild ? [] : [
98-
// we specify a custom UglifyJsPlugin here to get source maps in production
99-
new UglifyJsPlugin({
98+
// we specify a custom TerserPlugin here to get source maps in production
99+
new TerserPlugin({
100100
cache: true,
101101
parallel: true,
102-
uglifyOptions: {
102+
sourceMap: true,
103+
terserOptions: {
103104
compress: false,
104105
ecma: 6,
105106
mangle: true,
106107
keep_classnames: true,
107-
keep_fnames: true
108+
keep_fnames: true,
108109
},
109-
sourceMap: true
110110
})
111111
])
112112
}
@@ -141,18 +141,18 @@ module.exports = (env) => {
141141
].concat(isDevBuild ? [] : []),
142142
optimization: {
143143
minimizer: [].concat(isDevBuild ? [] : [
144-
// we specify a custom UglifyJsPlugin here to get source maps in production
145-
new UglifyJsPlugin({
144+
// we specify a custom TerserPlugin here to get source maps in production
145+
new TerserPlugin({
146146
cache: true,
147147
parallel: true,
148-
uglifyOptions: {
148+
sourceMap: true,
149+
terserOptions: {
149150
compress: false,
150151
ecma: 6,
151152
mangle: true,
152153
keep_classnames: true,
153-
keep_fnames: true
154+
keep_fnames: true,
154155
},
155-
sourceMap: true
156156
})
157157
])
158158
}

0 commit comments

Comments
 (0)