@@ -4,9 +4,43 @@ const path = require('path');
44const webpack = require ( 'webpack' ) ;
55const atl = require ( 'awesome-typescript-loader' ) ;
66
7- const getWebpackTestConfig = function ( projectRoot , environment , appConfig ) {
7+ const getWebpackTestConfig = function ( projectRoot , environment , appConfig , testConfig ) {
88
99 const appRoot = path . resolve ( projectRoot , appConfig . root ) ;
10+ const extraRules = [ ] ;
11+ const extraPlugins = [ ] ;
12+
13+ if ( testConfig . codeCoverage ) {
14+ extraRules . push ( {
15+ test : / \. ( j s | t s ) $ / , loader : 'sourcemap-istanbul-instrumenter-loader' ,
16+ enforce : 'post' ,
17+ exclude : [
18+ / \. ( e 2 e | s p e c ) \. t s $ / ,
19+ / n o d e _ m o d u l e s /
20+ ] ,
21+ query : { 'force-sourcemap' : true }
22+ } ) ;
23+ }
24+
25+ if ( testConfig . lint ) {
26+ extraRules . push ( {
27+ test : / \. t s $ / ,
28+ enforce : 'pre' ,
29+ loader : 'tslint-loader' ,
30+ exclude : [
31+ path . resolve ( projectRoot , 'node_modules' )
32+ ]
33+ } ) ;
34+ extraPlugins . push ( new webpack . LoaderOptionsPlugin ( {
35+ options : {
36+ tslint : {
37+ emitErrors : false ,
38+ failOnHint : false ,
39+ resourcePath : `./${ appConfig . root } `
40+ }
41+ }
42+ } ) )
43+ }
1044
1145 return {
1246 devtool : 'inline-source-map' ,
@@ -28,21 +62,12 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
2862 } ,
2963 module : {
3064 rules : [
31- {
32- test : / \. t s $ / ,
33- enforce : 'pre' ,
34- loader : 'tslint-loader' ,
35- exclude : [
36- path . resolve ( projectRoot , 'node_modules' )
37- ]
38- } ,
3965 {
4066 test : / \. j s $ / ,
4167 enforce : 'pre' ,
4268 loader : 'source-map-loader' ,
4369 exclude : [
44- path . resolve ( projectRoot , 'node_modules/rxjs' ) ,
45- path . resolve ( projectRoot , 'node_modules/@angular' )
70+ / n o d e _ m o d u l e s /
4671 ]
4772 } ,
4873 {
@@ -63,23 +88,14 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
6388 ] ,
6489 exclude : [ / \. e 2 e \. t s $ / ]
6590 } ,
66- {
67- test : / \. ( j s | t s ) $ / , loader : 'sourcemap-istanbul-instrumenter-loader' ,
68- enforce : 'post' ,
69- exclude : [
70- / \. ( e 2 e | s p e c ) \. t s $ / ,
71- / n o d e _ m o d u l e s /
72- ] ,
73- query : { 'force-sourcemap' : true }
74- } ,
7591 { test : / \. j s o n $ / , loader : 'json-loader' } ,
76- { test : / \. c s s $ / , loaders : [ 'raw-loader' , 'postcss-loader' ] } ,
92+ { test : / \. c s s $ / , loaders : [ 'raw-loader' , 'postcss-loader' ] } ,
7793 { test : / \. s t y l $ / , loaders : [ 'raw-loader' , 'postcss-loader' , 'stylus-loader' ] } ,
7894 { test : / \. l e s s $ / , loaders : [ 'raw-loader' , 'postcss-loader' , 'less-loader' ] } ,
7995 { test : / \. s c s s $ | \. s a s s $ / , loaders : [ 'raw-loader' , 'postcss-loader' , 'sass-loader' ] } ,
8096 { test : / \. ( j p g | p n g ) $ / , loader : 'url-loader?limit=128000' } ,
8197 { test : / \. h t m l $ / , loader : 'raw-loader' , exclude : [ path . resolve ( appRoot , appConfig . index ) ] }
82- ]
98+ ] . concat ( extraRules )
8399 } ,
84100 plugins : [
85101 new webpack . SourceMapDevToolPlugin ( {
@@ -94,20 +110,11 @@ const getWebpackTestConfig = function (projectRoot, environment, appConfig) {
94110 . replace ( / [ \- \[ \] \/ \{ \} \( \) \* \+ \? \. \\ \^ \$ \| ] / g, '\\$&' ) ) ,
95111 path . resolve ( appRoot , appConfig . environments [ environment ] )
96112 ) ,
97- new webpack . LoaderOptionsPlugin ( {
98- options : {
99- tslint : {
100- emitErrors : false ,
101- failOnHint : false ,
102- resourcePath : `./${ appConfig . root } `
103- }
104- }
105- } ) ,
106113 new webpack . ContextReplacementPlugin (
107114 / a n g u l a r ( \\ | \/ ) c o r e ( \\ | \/ ) ( e s m ( \\ | \/ ) s r c | s r c ) ( \\ | \/ ) l i n k e r / ,
108115 appRoot
109116 )
110- ] ,
117+ ] . concat ( extraPlugins ) ,
111118 node : {
112119 fs : 'empty' ,
113120 global : true ,
0 commit comments