@@ -2,19 +2,23 @@ import * as path from 'path';
22import * as webpack from 'webpack' ;
33import * as fs from 'fs' ;
44import * as semver from 'semver' ;
5+ import * as ts from 'typescript' ;
56import { stripIndent } from 'common-tags' ;
67import { LicenseWebpackPlugin } from 'license-webpack-plugin' ;
78import { PurifyPlugin } from '@angular-devkit/build-optimizer' ;
89import { StaticAssetPlugin } from '../../plugins/static-asset' ;
910import { GlobCopyWebpackPlugin } from '../../plugins/glob-copy-webpack-plugin' ;
1011import { WebpackConfigOptions } from '../webpack-config' ;
12+ import { readTsconfig } from '../../utilities/read-tsconfig' ;
13+
14+ const UglifyJSPlugin = require ( 'uglifyjs-webpack-plugin' ) ;
1115
1216
1317export const getProdConfig = function ( wco : WebpackConfigOptions ) {
1418 const { projectRoot, buildOptions, appConfig } = wco ;
1519
1620 let extraPlugins : any [ ] = [ ] ;
17- let entryPoints : { [ key : string ] : string [ ] } = { } ;
21+ let entryPoints : { [ key : string ] : string [ ] } = { } ;
1822
1923 if ( appConfig . serviceWorker ) {
2024 const nodeModules = path . resolve ( projectRoot , 'node_modules' ) ;
@@ -66,7 +70,7 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
6670 extraPlugins . push ( new GlobCopyWebpackPlugin ( {
6771 patterns : [
6872 '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 : '' }
7074 ] ,
7175 globOptions : {
7276 cwd : projectRoot ,
@@ -99,7 +103,7 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
99103 } ) ) ;
100104 }
101105
102- const uglifyCompressOptions : any = { screw_ie8 : true , warnings : buildOptions . verbose } ;
106+ const uglifyCompressOptions : any = { } ;
103107
104108 if ( buildOptions . buildOptimizer ) {
105109 // This plugin must be before webpack.optimize.UglifyJsPlugin.
@@ -110,21 +114,49 @@ export const getProdConfig = function (wco: WebpackConfigOptions) {
110114 uglifyCompressOptions . passes = 3 ;
111115 }
112116
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+
113151 return {
114152 entry : entryPoints ,
115- plugins : extraPlugins . concat ( [
153+ plugins : [
116154 new webpack . EnvironmentPlugin ( {
117155 'NODE_ENV' : 'production'
118156 } ) ,
119157 new webpack . HashedModuleIdsPlugin ( ) ,
120158 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+ ]
129161 } ;
130162} ;
0 commit comments