55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- // tslint:disable
9- // TODO: cleanup this file, it's copied as is from Angular CLI.
108
11- import * as path from 'path' ;
129import * as glob from 'glob' ;
13-
14- // import { CliConfig } from '../config ';
10+ import * as path from 'path' ;
11+ import * as webpack from 'webpack ' ;
1512import { WebpackConfigOptions , WebpackTestOptions } from '../build-options' ;
1613
1714
@@ -23,19 +20,20 @@ import { WebpackConfigOptions, WebpackTestOptions } from '../build-options';
2320 *
2421 */
2522
26-
27- export function getTestConfig ( wco : WebpackConfigOptions < WebpackTestOptions > ) {
23+ export function getTestConfig (
24+ wco : WebpackConfigOptions < WebpackTestOptions > ,
25+ ) : webpack . Configuration {
2826 const { root, buildOptions } = wco ;
2927
30- const extraRules : any [ ] = [ ] ;
31- const extraPlugins : any [ ] = [ ] ;
28+ const extraRules : webpack . Rule [ ] = [ ] ;
29+ const extraPlugins : webpack . Plugin [ ] = [ ] ;
3230
3331 // if (buildOptions.codeCoverage && CliConfig.fromProject()) {
3432 if ( buildOptions . codeCoverage ) {
3533 const codeCoverageExclude = buildOptions . codeCoverageExclude ;
36- let exclude : ( string | RegExp ) [ ] = [
34+ const exclude : ( string | RegExp ) [ ] = [
3735 / \. ( e 2 e | s p e c ) \. t s $ / ,
38- / n o d e _ m o d u l e s /
36+ / n o d e _ m o d u l e s / ,
3937 ] ;
4038
4139 if ( codeCoverageExclude ) {
@@ -51,7 +49,7 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
5149 test : / \. ( j s | t s ) $ / , loader : 'istanbul-instrumenter-loader' ,
5250 options : { esModules : true } ,
5351 enforce : 'post' ,
54- exclude
52+ exclude,
5553 } ) ;
5654 }
5755
@@ -60,34 +58,31 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
6058 resolve : {
6159 mainFields : [
6260 ...( wco . supportES2015 ? [ 'es2015' ] : [ ] ) ,
63- 'browser' , 'module' , 'main'
64- ]
61+ 'browser' , 'module' , 'main' ,
62+ ] ,
6563 } ,
6664 devtool : buildOptions . sourceMap ? 'inline-source-map' : 'eval' ,
6765 entry : {
68- main : path . resolve ( root , buildOptions . main )
66+ main : path . resolve ( root , buildOptions . main ) ,
6967 } ,
7068 module : {
71- rules : [ ] . concat ( extraRules as any )
69+ rules : extraRules ,
7270 } ,
7371 plugins : extraPlugins ,
7472 optimization : {
75- // runtimeChunk: 'single',
7673 splitChunks : {
77- chunks : buildOptions . commonChunk ? 'all' : 'initial' ,
74+ chunks : ( ( chunk : { name : string } ) => chunk . name !== 'polyfills' ) ,
7875 cacheGroups : {
7976 vendors : false ,
8077 vendor : {
8178 name : 'vendor' ,
8279 chunks : 'initial' ,
83- test : ( module : any , chunks : Array < { name : string } > ) => {
84- const moduleName = module . nameForCondition ? module . nameForCondition ( ) : '' ;
85- return / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / . test ( moduleName )
86- && ! chunks . some ( ( { name } ) => name === 'polyfills' ) ;
87- } ,
80+ test : / [ \\ / ] n o d e _ m o d u l e s [ \\ / ] / ,
8881 } ,
89- }
90- }
82+ } ,
83+ } ,
9184 } ,
92- } ;
85+ // Webpack typings don't yet include the function form for 'chunks',
86+ // or the built-in vendors cache group.
87+ } as { } as webpack . Configuration ;
9388}
0 commit comments