5
5
* Use of this source code is governed by an MIT-style license that can be
6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
- // tslint:disable
9
- // TODO: cleanup this file, it's copied as is from Angular CLI.
10
8
11
- import * as path from 'path' ;
12
9
import * as glob from 'glob' ;
13
-
14
- // import { CliConfig } from '../config ';
10
+ import * as path from 'path' ;
11
+ import * as webpack from 'webpack ' ;
15
12
import { WebpackConfigOptions , WebpackTestOptions } from '../build-options' ;
16
13
17
14
@@ -23,19 +20,20 @@ import { WebpackConfigOptions, WebpackTestOptions } from '../build-options';
23
20
*
24
21
*/
25
22
26
-
27
- export function getTestConfig ( wco : WebpackConfigOptions < WebpackTestOptions > ) {
23
+ export function getTestConfig (
24
+ wco : WebpackConfigOptions < WebpackTestOptions > ,
25
+ ) : webpack . Configuration {
28
26
const { root, buildOptions } = wco ;
29
27
30
- const extraRules : any [ ] = [ ] ;
31
- const extraPlugins : any [ ] = [ ] ;
28
+ const extraRules : webpack . Rule [ ] = [ ] ;
29
+ const extraPlugins : webpack . Plugin [ ] = [ ] ;
32
30
33
31
// if (buildOptions.codeCoverage && CliConfig.fromProject()) {
34
32
if ( buildOptions . codeCoverage ) {
35
33
const codeCoverageExclude = buildOptions . codeCoverageExclude ;
36
- let exclude : ( string | RegExp ) [ ] = [
34
+ const exclude : ( string | RegExp ) [ ] = [
37
35
/ \. ( 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 / ,
39
37
] ;
40
38
41
39
if ( codeCoverageExclude ) {
@@ -51,7 +49,7 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
51
49
test : / \. ( j s | t s ) $ / , loader : 'istanbul-instrumenter-loader' ,
52
50
options : { esModules : true } ,
53
51
enforce : 'post' ,
54
- exclude
52
+ exclude,
55
53
} ) ;
56
54
}
57
55
@@ -60,34 +58,31 @@ export function getTestConfig(wco: WebpackConfigOptions<WebpackTestOptions>) {
60
58
resolve : {
61
59
mainFields : [
62
60
...( wco . supportES2015 ? [ 'es2015' ] : [ ] ) ,
63
- 'browser' , 'module' , 'main'
64
- ]
61
+ 'browser' , 'module' , 'main' ,
62
+ ] ,
65
63
} ,
66
64
devtool : buildOptions . sourceMap ? 'inline-source-map' : 'eval' ,
67
65
entry : {
68
- main : path . resolve ( root , buildOptions . main )
66
+ main : path . resolve ( root , buildOptions . main ) ,
69
67
} ,
70
68
module : {
71
- rules : [ ] . concat ( extraRules as any )
69
+ rules : extraRules ,
72
70
} ,
73
71
plugins : extraPlugins ,
74
72
optimization : {
75
- // runtimeChunk: 'single',
76
73
splitChunks : {
77
- chunks : buildOptions . commonChunk ? 'all' : 'initial' ,
74
+ chunks : ( ( chunk : { name : string } ) => chunk . name !== 'polyfills' ) ,
78
75
cacheGroups : {
79
76
vendors : false ,
80
77
vendor : {
81
78
name : 'vendor' ,
82
79
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 [ \\ / ] / ,
88
81
} ,
89
- }
90
- }
82
+ } ,
83
+ } ,
91
84
} ,
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 ;
93
88
}
0 commit comments