@@ -35,17 +35,14 @@ module.exports = function makeWebpackConfig() {
35
35
*/
36
36
if ( isProd ) {
37
37
config . devtool = 'source-map' ;
38
- }
38
+ }
39
39
else if ( isTest ) {
40
40
config . devtool = 'inline-source-map' ;
41
41
}
42
42
else {
43
43
config . devtool = 'eval-source-map' ;
44
44
}
45
45
46
- // add debug messages
47
- config . debug = ! isProd || ! isTest ;
48
-
49
46
/**
50
47
* Entry
51
48
* Reference: http://webpack.github.io/docs/configuration.html#entry
@@ -72,21 +69,15 @@ module.exports = function makeWebpackConfig() {
72
69
* Reference: http://webpack.github.io/docs/configuration.html#resolve
73
70
*/
74
71
config . resolve = {
75
- cache : ! isTest ,
76
- root : root ( ) ,
77
72
// only discover files that have those extensions
78
- extensions : [ '' , '.ts' , '.js' , '.json' , '.css' , '.scss' , '.html' ] ,
79
- alias : {
80
- 'app' : 'src/app' ,
81
- 'common' : 'src/common'
82
- }
73
+ extensions : [ '.ts' , '.js' , '.json' , '.css' , '.scss' , '.html' ] ,
83
74
} ;
84
75
85
76
var atlOptions = '' ;
86
77
if ( isTest && ! isTestWatch ) {
87
78
// awesome-typescript-loader needs to output inlineSourceMap for code coverage to work with source maps.
88
79
atlOptions = 'inlineSourceMap=true&sourceMap=false' ;
89
- }
80
+ }
90
81
91
82
/**
92
83
* Loaders
@@ -95,8 +86,7 @@ module.exports = function makeWebpackConfig() {
95
86
* This handles most of the magic responsible for converting modules
96
87
*/
97
88
config . module = {
98
- preLoaders : isTest ? [ ] : [ { test : / \. t s $ / , loader : 'tslint' } ] ,
99
- loaders : [
89
+ rules : [
100
90
// Support for .ts files.
101
91
{
102
92
test : / \. t s $ / ,
@@ -119,7 +109,7 @@ module.exports = function makeWebpackConfig() {
119
109
{
120
110
test : / \. c s s $ / ,
121
111
exclude : root ( 'src' , 'app' ) ,
122
- loader : isTest ? 'null' : ExtractTextPlugin . extract ( 'style' , 'css?sourceMap! postcss' )
112
+ loader : isTest ? 'null' : ExtractTextPlugin . extract ( { fallbackLoader : 'style-loader ' , loader : [ 'css' , ' postcss'] } )
123
113
} ,
124
114
// all css required in src/app files will be merged in js files
125
115
{ test : / \. c s s $ / , include : root ( 'src' , 'app' ) , loader : 'raw!postcss' } ,
@@ -130,28 +120,37 @@ module.exports = function makeWebpackConfig() {
130
120
{
131
121
test : / \. s c s s $ / ,
132
122
exclude : root ( 'src' , 'app' ) ,
133
- loader : isTest ? 'null' : ExtractTextPlugin . extract ( 'style' , 'css?sourceMap! postcss! sass' )
123
+ loader : isTest ? 'null' : ExtractTextPlugin . extract ( { fallbackLoader : 'style-loader ' , loader : [ 'css' , ' postcss' , ' sass'] } )
134
124
} ,
135
125
// all css required in src/app files will be merged in js files
136
126
{ test : / \. s c s s $ / , exclude : root ( 'src' , 'style' ) , loader : 'raw!postcss!sass' } ,
137
127
138
128
// support for .html as raw text
139
129
// todo: change the loader to something that adds a hash to images
140
130
{ test : / \. h t m l $ / , loader : 'raw' , exclude : root ( 'src' , 'public' ) }
141
- ] ,
142
- postLoaders : [ ]
131
+ ]
143
132
} ;
144
133
145
134
if ( isTest && ! isTestWatch ) {
146
135
// instrument only testing sources with Istanbul, covers ts files
147
- config . module . postLoaders . push ( {
136
+ config . module . rules . push ( {
148
137
test : / \. t s $ / ,
138
+ enforce : 'post' ,
149
139
include : path . resolve ( 'src' ) ,
150
140
loader : 'istanbul-instrumenter-loader' ,
151
141
exclude : [ / \. s p e c \. t s $ / , / \. e 2 e \. t s $ / , / n o d e _ m o d u l e s / ]
152
142
} ) ;
153
143
}
154
144
145
+ if ( ! isTest || ! isTestWatch ) {
146
+ // tslint support
147
+ config . module . rules . push ( {
148
+ test : / \. t s $ / ,
149
+ enforce : 'pre' ,
150
+ loader : 'tslint'
151
+ } ) ;
152
+ }
153
+
155
154
/**
156
155
* Plugins
157
156
* Reference: http://webpack.github.io/docs/configuration.html#plugins
@@ -165,14 +164,53 @@ module.exports = function makeWebpackConfig() {
165
164
'process.env' : {
166
165
ENV : JSON . stringify ( ENV )
167
166
}
167
+ } ) ,
168
+
169
+ // Workaround needed for angular 2 angular/angular#11580
170
+ new webpack . ContextReplacementPlugin (
171
+ // The (\\|\/) piece accounts for path separators in *nix and Windows
172
+ / 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 / ,
173
+ root ( './src' ) // location of your src
174
+ ) ,
175
+
176
+ // Tslint configuration for webpack 2
177
+ new webpack . LoaderOptionsPlugin ( {
178
+ options : {
179
+ /**
180
+ * Apply the tslint loader as pre/postLoader
181
+ * Reference: https://github.com/wbuchwalter/tslint-loader
182
+ */
183
+ tslint : {
184
+ emitErrors : false ,
185
+ failOnHint : false
186
+ } ,
187
+ /**
188
+ * Sass
189
+ * Reference: https://github.com/jtangelder/sass-loader
190
+ * Transforms .scss files to .css
191
+ */
192
+ sassLoader : {
193
+ //includePaths: [path.resolve(__dirname, "node_modules/foundation-sites/scss")]
194
+ } ,
195
+ /**
196
+ * PostCSS
197
+ * Reference: https://github.com/postcss/autoprefixer-core
198
+ * Add vendor prefixes to your css
199
+ */
200
+ postcss : [
201
+ autoprefixer ( {
202
+ browsers : [ 'last 2 version' ]
203
+ } )
204
+ ]
205
+ }
168
206
} )
169
207
] ;
170
208
171
209
if ( ! isTest && ! isProd ) {
172
210
config . plugins . push ( new DashboardPlugin ( ) ) ;
173
211
}
174
212
175
- if ( ! isTest ) {
213
+ if ( ! isTest && ! isTestWatch ) {
176
214
config . plugins . push (
177
215
new ForkCheckerPlugin ( ) ,
178
216
@@ -193,7 +231,7 @@ module.exports = function makeWebpackConfig() {
193
231
// Extract css files
194
232
// Reference: https://github.com/webpack/extract-text-webpack-plugin
195
233
// Disabled when in test mode or not in build mode
196
- new ExtractTextPlugin ( 'css/[name].[hash].css' , { disable : ! isProd } )
234
+ new ExtractTextPlugin ( { filename : 'css/[name].[hash].css' , disable : ! isProd } )
197
235
) ;
198
236
}
199
237
@@ -204,13 +242,13 @@ module.exports = function makeWebpackConfig() {
204
242
// Only emit files when there are no errors
205
243
new webpack . NoErrorsPlugin ( ) ,
206
244
207
- // Reference: http://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
208
- // Dedupe modules in the output
209
- new webpack . optimize . DedupePlugin ( ) ,
245
+ // // Reference: http://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
246
+ // // Dedupe modules in the output
247
+ // new webpack.optimize.DedupePlugin(),
210
248
211
249
// Reference: http://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
212
250
// Minify all javascript, switch loaders to minimizing mode
213
- new webpack . optimize . UglifyJsPlugin ( { mangle : { keep_fnames : true } } ) ,
251
+ new webpack . optimize . UglifyJsPlugin ( { sourceMap : true , mangle : { keep_fnames : true } } ) ,
214
252
215
253
// Copy assets from the public folder
216
254
// Reference: https://github.com/kevlened/copy-webpack-plugin
@@ -220,35 +258,6 @@ module.exports = function makeWebpackConfig() {
220
258
) ;
221
259
}
222
260
223
- /**
224
- * PostCSS
225
- * Reference: https://github.com/postcss/autoprefixer-core
226
- * Add vendor prefixes to your css
227
- */
228
- config . postcss = [
229
- autoprefixer ( {
230
- browsers : [ 'last 2 version' ]
231
- } )
232
- ] ;
233
-
234
- /**
235
- * Sass
236
- * Reference: https://github.com/jtangelder/sass-loader
237
- * Transforms .scss files to .css
238
- */
239
- config . sassLoader = {
240
- //includePaths: [path.resolve(__dirname, "node_modules/foundation-sites/scss")]
241
- } ;
242
-
243
- /**
244
- * Apply the tslint loader as pre/postLoader
245
- * Reference: https://github.com/wbuchwalter/tslint-loader
246
- */
247
- config . tslint = {
248
- emitErrors : false ,
249
- failOnHint : false
250
- } ;
251
-
252
261
/**
253
262
* Dev server configuration
254
263
* Reference: http://webpack.github.io/docs/configuration.html#devserver
0 commit comments