1
1
/* webpack.test.js */
2
- /**
3
- * @author : @AngularClass
4
- */
5
-
2
+ const webpack = require ( 'webpack' ) ;
6
3
const helpers = require ( './helpers' ) ;
7
-
8
- /**
9
- * Webpack Plugins
10
- */
11
4
const ProvidePlugin = require ( 'webpack/lib/ProvidePlugin' ) ;
12
5
const DefinePlugin = require ( 'webpack/lib/DefinePlugin' ) ;
13
-
14
- /**
15
- * Webpack Constants
16
- */
17
6
const ENV = process . env . ENV = process . env . NODE_ENV = 'test' ;
18
7
19
- /**
20
- * Webpack configuration
21
- *
22
- * See: http://webpack.github.io/docs/configuration.html#cli
23
- */
24
8
module . exports = {
25
-
26
- /**
27
- * Source map for Karma from the help of karma-sourcemap-loader & karma-webpack
28
- *
29
- * Do not change, leave as is or it wont work.
30
- * See: https://github.com/webpack/karma-webpack#source-maps
31
- */
32
9
devtool : 'inline-source-map' ,
33
10
34
- /**
35
- * Options affecting the resolving of modules.
36
- *
37
- * See: http://webpack.github.io/docs/configuration.html#resolve
38
- */
39
11
resolve : {
40
-
41
- /**
42
- * An array of extensions that should be used to resolve modules.
43
- *
44
- * See: http://webpack.github.io/docs/configuration.html#resolve-extensions
45
- */
46
- extensions : [ '' , '.ts' , '.js' ] ,
47
-
48
- /**
49
- * Make sure root is src
50
- */
51
- root : helpers . root ( 'src' ) ,
52
-
12
+ extensions : [ '.ts' , '.js' ] ,
13
+ modules : [ helpers . root ( 'src' ) , 'node_modules' ]
53
14
} ,
54
15
55
- /**
56
- * Options affecting the normal modules.
57
- *
58
- * See: http://webpack.github.io/docs/configuration.html#module
59
- */
60
16
module : {
61
-
62
- /**
63
- * An array of applied pre and post loaders.
64
- *
65
- * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
66
- */
67
- preLoaders : [
68
-
69
- /**
70
- * Tslint loader support for *.ts files
71
- *
72
- * See: https://github.com/wbuchwalter/tslint-loader
73
- */
17
+ rules : [
74
18
{
75
19
test : / \. t s $ / ,
76
20
loader : 'tslint-loader' ,
21
+ enforce : 'pre' ,
77
22
exclude : [ helpers . root ( 'node_modules' ) ]
78
23
} ,
79
-
80
- /**
81
- * Source map loader support for *.js files
82
- * Extracts SourceMaps for source files that as added as sourceMappingURL comment.
83
- *
84
- * See: https://github.com/webpack/source-map-loader
85
- */
86
24
{
87
25
test : / \. j s $ / ,
88
26
loader : 'source-map-loader' ,
27
+ enforce : 'pre' ,
89
28
exclude : [
90
- // these packages have problems with their sourcemaps
91
- helpers . root ( 'node_modules/rxjs' ) ,
92
- helpers . root ( 'node_modules/@angular' )
93
- ] }
94
-
95
- ] ,
96
-
97
- /**
98
- * An array of automatically applied loaders.
99
- *
100
- * IMPORTANT: The loaders here are resolved relative to the resource which they are applied to.
101
- * This means they are not resolved relative to the configuration file.
102
- *
103
- * See: http://webpack.github.io/docs/configuration.html#module-loaders
104
- */
105
- loaders : [
106
-
107
- /**
108
- * Typescript loader support for .ts and Angular 2 async routes via .async.ts
109
- *
110
- * See: https://github.com/s-panferov/awesome-typescript-loader
111
- */
29
+ helpers . root ( 'node_modules/rxjs' ) ,
30
+ helpers . root ( 'node_modules/@angular' )
31
+ ]
32
+ } ,
112
33
{
113
34
test : / \. t s $ / ,
114
35
loader : 'awesome-typescript-loader' ,
115
36
query : {
116
37
compilerOptions : {
117
-
118
- // Remove TypeScript helpers to be injected
119
- // below by DefinePlugin
120
38
removeComments : true
121
-
122
39
}
123
40
} ,
124
41
exclude : [ / \. e 2 e \. t s $ / ]
125
42
} ,
126
-
127
- /**
128
- * Json loader support for *.json files.
129
- *
130
- * See: https://github.com/webpack/json-loader
131
- */
132
- { test : / \. j s o n $ / , loader : 'json-loader' , exclude : [ helpers . root ( 'src/index.html' ) ] } ,
133
-
134
- /**
135
- * Raw loader support for *.css files
136
- * Returns file content as string
137
- *
138
- * See: https://github.com/webpack/raw-loader
139
- */
140
- { test : / \. c s s $ / , loaders : [ 'to-string-loader' , 'css-loader' ] , exclude : [ helpers . root ( 'src/index.html' ) ] } ,
141
-
142
- /**
143
- * Raw loader support for *.html
144
- * Returns file content as string
145
- *
146
- * See: https://github.com/webpack/raw-loader
147
- */
148
- { test : / \. h t m l $ / , loader : 'raw-loader' , exclude : [ helpers . root ( 'src/index.html' ) ] }
149
-
150
- ] ,
151
-
152
- /**
153
- * An array of applied pre and post loaders.
154
- *
155
- * See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders
156
- */
157
- postLoaders : [
158
-
159
- /**
160
- * Instruments JS files with Istanbul for subsequent code coverage reporting.
161
- * Instrument only testing sources.
162
- *
163
- * See: https://github.com/deepsweet/istanbul-instrumenter-loader
164
- */
43
+ {
44
+ test : / \. j s o n $ / ,
45
+ loader : 'json-loader' ,
46
+ exclude : [ helpers . root ( 'src/index.html' ) ]
47
+ } ,
48
+ {
49
+ test : / \. c s s $ / , loaders : [ 'to-string-loader' , 'css-loader' ] ,
50
+ exclude : [ helpers . root ( 'src/index.html' ) ]
51
+ } ,
52
+ {
53
+ test : / \. h t m l $ / ,
54
+ loader : 'raw-loader' ,
55
+ exclude : [ helpers . root ( 'src/index.html' ) ]
56
+ } ,
165
57
{
166
58
test : / \. ( j s | t s ) $ / , loader : 'istanbul-instrumenter-loader' ,
167
59
include : helpers . root ( 'src' ) ,
60
+ enforce : 'post' ,
168
61
exclude : [
169
62
/ \. ( e 2 e | s p e c ) \. t s $ / ,
170
63
/ n o d e _ m o d u l e s /
171
64
]
172
65
}
173
-
174
66
]
175
67
} ,
176
68
177
- /**
178
- * Add additional plugins to the compiler.
179
- *
180
- * See: http://webpack.github.io/docs/configuration.html#plugins
181
- */
182
69
plugins : [
183
-
184
- /**
185
- * Plugin: DefinePlugin
186
- * Description: Define free variables.
187
- * Useful for having development builds with debug logging or adding global constants.
188
- *
189
- * Environment helpers
190
- *
191
- * See: https://webpack.github.io/docs/list-of-plugins.html#defineplugin
192
- */
193
- // NOTE: when adding more properties make sure you include them in custom-typings.d.ts
194
70
new DefinePlugin ( {
195
71
'ENV' : JSON . stringify ( ENV ) ,
196
72
'HMR' : false ,
@@ -201,31 +77,21 @@ module.exports = {
201
77
}
202
78
} ) ,
203
79
204
-
80
+ new webpack . LoaderOptionsPlugin ( {
81
+ options : {
82
+ tslint : {
83
+ emitErrors : false ,
84
+ failOnHint : false ,
85
+ resourcePath : 'src'
86
+ }
87
+ }
88
+ } )
205
89
] ,
206
90
207
- /**
208
- * Static analysis linter for TypeScript advanced options configuration
209
- * Description: An extensible linter for the TypeScript language.
210
- *
211
- * See: https://github.com/wbuchwalter/tslint-loader
212
- */
213
- tslint : {
214
- emitErrors : false ,
215
- failOnHint : false ,
216
- resourcePath : 'src'
217
- } ,
218
-
219
- /**
220
- * Include polyfills or mocks for various node stuff
221
- * Description: Node configuration
222
- *
223
- * See: https://webpack.github.io/docs/configuration.html#node
224
- */
225
91
node : {
226
- global : 'window' ,
92
+ global : true ,
227
93
process : false ,
228
- crypto : 'empty' ,
94
+ crypto : false ,
229
95
module : false ,
230
96
clearImmediate : false ,
231
97
setImmediate : false
0 commit comments