8
8
import { tags } from '@angular-devkit/core' ;
9
9
import * as CopyWebpackPlugin from 'copy-webpack-plugin' ;
10
10
import * as path from 'path' ;
11
+ import * as ts from 'typescript' ;
11
12
import {
12
13
Configuration ,
13
14
ContextReplacementPlugin ,
@@ -21,8 +22,8 @@ import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin';
21
22
import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin' ;
22
23
import { findAllNodeModules , findUp } from '../../utilities/find-up' ;
23
24
import { requireProjectModule } from '../../utilities/require-project-module' ;
24
- import { BuildOptions , WebpackConfigOptions } from '../build-options' ;
25
- import { getOutputHashFormat , normalizeExtraEntryPoints } from './utils' ;
25
+ import { WebpackConfigOptions } from '../build-options' ;
26
+ import { getEsVersionForFileName , getOutputHashFormat , normalizeExtraEntryPoints } from './utils' ;
26
27
27
28
const ProgressPlugin = require ( 'webpack/lib/ProgressPlugin' ) ;
28
29
const CircularDependencyPlugin = require ( 'circular-dependency-plugin' ) ;
@@ -55,35 +56,48 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
55
56
const extraPlugins : any [ ] = [ ] ;
56
57
const entryPoints : { [ key : string ] : string [ ] } = { } ;
57
58
59
+ const targetInFileName = getEsVersionForFileName (
60
+ buildOptions . scriptTargetOverride ,
61
+ buildOptions . esVersionInFileName ,
62
+ ) ;
63
+
58
64
if ( buildOptions . main ) {
59
65
entryPoints [ 'main' ] = [ path . resolve ( root , buildOptions . main ) ] ;
60
66
}
61
67
68
+ const es5Polyfills = path . join ( __dirname , '..' , 'es5-polyfills.js' ) ;
62
69
if ( buildOptions . es5BrowserSupport ) {
63
- entryPoints [ 'polyfills.es5' ] = [ path . join ( __dirname , '..' , 'es5-polyfills.js' ) ] ;
70
+ entryPoints [ 'polyfills.es5' ] = [ es5Polyfills ] ;
71
+ if ( ! buildOptions . aot ) {
72
+ entryPoints [ 'polyfills.es5' ] . push ( path . join ( __dirname , '..' , 'es5-jit-polyfills.js' ) ) ;
73
+ }
74
+ }
75
+
76
+ if ( buildOptions . es5BrowserSupport === undefined
77
+ && buildOptions . scriptTargetOverride === ts . ScriptTarget . ES5 ) {
78
+ entryPoints [ 'polyfills' ] = [ es5Polyfills ] ;
79
+ if ( ! buildOptions . aot ) {
80
+ entryPoints [ 'polyfills' ] . push ( path . join ( __dirname , '..' , 'es5-jit-polyfills.js' ) ) ;
81
+ }
64
82
}
65
83
66
84
if ( buildOptions . polyfills ) {
67
- entryPoints [ 'polyfills' ] = [ path . resolve ( root , buildOptions . polyfills ) ] ;
85
+ entryPoints [ 'polyfills' ] = [
86
+ ...( entryPoints [ 'polyfills' ] || [ ] ) ,
87
+ path . resolve ( root , buildOptions . polyfills ) ,
88
+ ] ;
68
89
}
69
90
70
91
if ( ! buildOptions . aot ) {
71
92
entryPoints [ 'polyfills' ] = [
72
93
...( entryPoints [ 'polyfills' ] || [ ] ) ,
73
94
path . join ( __dirname , '..' , 'jit-polyfills.js' ) ,
74
95
] ;
75
-
76
- if ( buildOptions . es5BrowserSupport ) {
77
- entryPoints [ 'polyfills.es5' ] = [
78
- ...entryPoints [ 'polyfills.es5' ] ,
79
- path . join ( __dirname , '..' , 'es5-jit-polyfills.js' ) ,
80
- ] ;
81
- }
82
96
}
83
97
84
98
if ( buildOptions . profile || process . env [ 'NG_BUILD_PROFILING' ] ) {
85
99
extraPlugins . push ( new debug . ProfilingPlugin ( {
86
- outputPath : path . resolve ( root , ' chrome-profiler-events.json' ) ,
100
+ outputPath : path . resolve ( root , ` chrome-profiler-events${ targetInFileName } .json` ) ,
87
101
} ) ) ;
88
102
}
89
103
@@ -104,7 +118,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
104
118
}
105
119
106
120
existingEntry . paths . push ( resolvedPath ) ;
107
-
108
121
} else {
109
122
prev . push ( {
110
123
bundleName,
@@ -177,7 +190,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
177
190
}
178
191
179
192
if ( buildOptions . statsJson ) {
180
- extraPlugins . push ( new StatsPlugin ( ' stats.json' , 'verbose' ) ) ;
193
+ extraPlugins . push ( new StatsPlugin ( ` stats${ targetInFileName } .json` , 'verbose' ) ) ;
181
194
}
182
195
183
196
let sourceMapUseRule ;
@@ -305,7 +318,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
305
318
futureEmitAssets : true ,
306
319
path : path . resolve ( root , buildOptions . outputPath as string ) ,
307
320
publicPath : buildOptions . deployUrl ,
308
- filename : `[name]${ hashFormat . chunk } .js` ,
321
+ filename : `[name]${ targetInFileName } ${ hashFormat . chunk } .js` ,
309
322
// cast required until typings include `futureEmitAssets` property
310
323
} as Output ,
311
324
watch : buildOptions . watch ,
0 commit comments