@@ -2,19 +2,23 @@ import * as path from 'path';
2
2
import * as webpack from 'webpack' ;
3
3
import * as fs from 'fs' ;
4
4
import * as semver from 'semver' ;
5
+ import * as ts from 'typescript' ;
5
6
import { stripIndent } from 'common-tags' ;
6
7
import { LicenseWebpackPlugin } from 'license-webpack-plugin' ;
7
8
import { PurifyPlugin } from '@angular-devkit/build-optimizer' ;
8
9
import { StaticAssetPlugin } from '../../plugins/static-asset' ;
9
10
import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin' ;
10
11
import { WebpackConfigOptions } from '../webpack-config' ;
12
+ import { readTsconfig } from '../../utilities/read-tsconfig' ;
13
+
14
+ const UglifyJSPlugin = require ( 'uglifyjs-webpack-plugin' ) ;
11
15
12
16
13
17
export const getProdConfig = function ( wco : WebpackConfigOptions ) {
14
18
const { projectRoot, buildOptions, appConfig } = wco ;
15
19
16
20
let extraPlugins : any [ ] = [ ] ;
17
- let entryPoints : { [ key : string ] : string [ ] } = { } ;
21
+ let entryPoints : { [ key : string ] : string [ ] } = { } ;
18
22
19
23
if ( appConfig . serviceWorker ) {
20
24
const nodeModules = path . resolve ( projectRoot , 'node_modules' ) ;
@@ -66,7 +70,7 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
66
70
extraPlugins . push ( new GlobCopyWebpackPlugin ( {
67
71
patterns : [
68
72
'ngsw-manifest.json' ,
69
- { glob : 'ngsw-manifest.json' , input : path . resolve ( projectRoot , appConfig . root ) , output : '' }
73
+ { glob : 'ngsw-manifest.json' , input : path . resolve ( projectRoot , appConfig . root ) , output : '' }
70
74
] ,
71
75
globOptions : {
72
76
cwd : projectRoot ,
@@ -99,7 +103,7 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
99
103
} ) ) ;
100
104
}
101
105
102
- const uglifyCompressOptions : any = { screw_ie8 : true , warnings : buildOptions . verbose } ;
106
+ const uglifyCompressOptions : any = { } ;
103
107
104
108
if ( buildOptions . buildOptimizer ) {
105
109
// This plugin must be before webpack.optimize.UglifyJsPlugin.
@@ -110,21 +114,49 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
110
114
uglifyCompressOptions . passes = 3 ;
111
115
}
112
116
117
+ // Read the tsconfig to determine if we should apply ES6 uglify.
118
+ const tsconfigPath = path . resolve ( projectRoot , appConfig . root , appConfig . tsconfig ) ;
119
+ const tsConfig = readTsconfig ( tsconfigPath ) ;
120
+ const supportES2015 = tsConfig . options . target !== ts . ScriptTarget . ES3
121
+ && tsConfig . options . target !== ts . ScriptTarget . ES5 ;
122
+
123
+ if ( supportES2015 ) {
124
+ extraPlugins . push ( new UglifyJSPlugin ( {
125
+ sourceMap : buildOptions . sourcemaps ,
126
+ uglifyOptions : {
127
+ ecma : 6 ,
128
+ warnings : buildOptions . verbose ,
129
+ ie8 : false ,
130
+ mangle : true ,
131
+ compress : uglifyCompressOptions ,
132
+ output : {
133
+ ascii_only : true ,
134
+ comments : false
135
+ } ,
136
+ }
137
+ } ) ) ;
138
+ } else {
139
+ uglifyCompressOptions . screw_ie8 = true ;
140
+ uglifyCompressOptions . warnings = buildOptions . verbose ;
141
+ extraPlugins . push ( new webpack . optimize . UglifyJsPlugin ( < any > {
142
+ mangle : { screw_ie8 : true } ,
143
+ compress : uglifyCompressOptions ,
144
+ output : { ascii_only : true } ,
145
+ sourceMap : buildOptions . sourcemaps ,
146
+ comments : false
147
+ } ) ) ;
148
+
149
+ }
150
+
113
151
return {
114
152
entry : entryPoints ,
115
- plugins : extraPlugins . concat ( [
153
+ plugins : [
116
154
new webpack . EnvironmentPlugin ( {
117
155
'NODE_ENV' : 'production'
118
156
} ) ,
119
157
new webpack . HashedModuleIdsPlugin ( ) ,
120
158
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
- ] )
159
+ ...extraPlugins
160
+ ]
129
161
} ;
130
162
} ;
0 commit comments