@@ -9,12 +9,14 @@ import { StaticAssetPlugin } from '../../plugins/static-asset';
9
9
import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin' ;
10
10
import { WebpackConfigOptions } from '../webpack-config' ;
11
11
12
+ const UglifyJSPlugin = require ( 'uglifyjs-webpack-plugin' ) ;
13
+
12
14
13
15
export const getProdConfig = function ( wco : WebpackConfigOptions ) {
14
16
const { projectRoot, buildOptions, appConfig } = wco ;
15
17
16
18
let extraPlugins : any [ ] = [ ] ;
17
- let entryPoints : { [ key : string ] : string [ ] } = { } ;
19
+ let entryPoints : { [ key : string ] : string [ ] } = { } ;
18
20
19
21
if ( appConfig . serviceWorker ) {
20
22
const nodeModules = path . resolve ( projectRoot , 'node_modules' ) ;
@@ -66,7 +68,7 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
66
68
extraPlugins . push ( new GlobCopyWebpackPlugin ( {
67
69
patterns : [
68
70
'ngsw-manifest.json' ,
69
- { glob : 'ngsw-manifest.json' , input : path . resolve ( projectRoot , appConfig . root ) , output : '' }
71
+ { glob : 'ngsw-manifest.json' , input : path . resolve ( projectRoot , appConfig . root ) , output : '' }
70
72
] ,
71
73
globOptions : {
72
74
cwd : projectRoot ,
@@ -99,7 +101,7 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
99
101
} ) ) ;
100
102
}
101
103
102
- const uglifyCompressOptions : any = { screw_ie8 : true , warnings : buildOptions . verbose } ;
104
+ const uglifyCompressOptions : any = { } ;
103
105
104
106
if ( buildOptions . buildOptimizer ) {
105
107
// This plugin must be before webpack.optimize.UglifyJsPlugin.
@@ -110,21 +112,43 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
110
112
uglifyCompressOptions . passes = 3 ;
111
113
}
112
114
115
+ if ( buildOptions . compilationTarget === 'ES2015' ) {
116
+ extraPlugins . push ( new UglifyJSPlugin ( {
117
+ sourceMap : buildOptions . sourcemaps ,
118
+ uglifyOptions : {
119
+ ecma : 6 ,
120
+ warnings : buildOptions . verbose ,
121
+ ie8 : false ,
122
+ mangle : true ,
123
+ compress : uglifyCompressOptions ,
124
+ output : {
125
+ ascii_only : true ,
126
+ comments : false
127
+ } ,
128
+ }
129
+ } ) ) ;
130
+ } else {
131
+ uglifyCompressOptions . screw_ie8 = true ;
132
+ uglifyCompressOptions . warnings = buildOptions . verbose ;
133
+ extraPlugins . push ( new webpack . optimize . UglifyJsPlugin ( < any > {
134
+ mangle : { screw_ie8 : true } ,
135
+ compress : uglifyCompressOptions ,
136
+ output : { ascii_only : true } ,
137
+ sourceMap : buildOptions . sourcemaps ,
138
+ comments : false
139
+ } ) ) ;
140
+
141
+ }
142
+
113
143
return {
114
144
entry : entryPoints ,
115
- plugins : extraPlugins . concat ( [
145
+ plugins : [
116
146
new webpack . EnvironmentPlugin ( {
117
147
'NODE_ENV' : 'production'
118
148
} ) ,
119
149
new webpack . HashedModuleIdsPlugin ( ) ,
120
150
new webpack . optimize . ModuleConcatenationPlugin ( ) ,
121
- new webpack . optimize . UglifyJsPlugin ( < any > {
122
- mangle : { screw_ie8 : true } ,
123
- compress : uglifyCompressOptions ,
124
- output : { ascii_only : true } ,
125
- sourceMap : buildOptions . sourcemaps ,
126
- comments : false
127
- } )
128
- ] )
151
+ ...extraPlugins
152
+ ]
129
153
} ;
130
154
} ;
0 commit comments