@@ -131,9 +131,16 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
131
131
132
132
// The webpack tier owns the watch behavior so we want to force it in the config
133
133
webpackConfig . watch = true ;
134
+ // Files need to be served from a custom path for Karma.
134
135
webpackConfig . output . path = '/_karma_webpack_/' ;
135
136
webpackConfig . output . publicPath = '/_karma_webpack_/' ;
136
137
138
+
139
+ // webpackConfig.entry = Object.assign({}, {
140
+ // scripts: [],
141
+ // styles: []
142
+ // }, webpackConfig.entry)
143
+
137
144
let compiler : any ;
138
145
try {
139
146
compiler = webpack ( webpackConfig ) ;
@@ -168,8 +175,22 @@ const init: any = (config: any, emitter: any, customFileHandlers: any) => {
168
175
urlRegex : / ^ \/ _ k a r m a _ w e b p a c k _ \/ .* / ,
169
176
handler : function handler ( req : any , res : any ) {
170
177
middleware ( req , res , function ( ) {
171
- res . statusCode = 404 ;
172
- res . end ( 'Not found' ) ;
178
+ // Ensure script and style bundles are served.
179
+ // They are mentioned in the custom karma context page and we don't want them to 404.
180
+ const alwaysServe = [
181
+ '/_karma_webpack_/inline.bundle.js' ,
182
+ '/_karma_webpack_/polyfills.bundle.js' ,
183
+ '/_karma_webpack_/scripts.bundle.js' ,
184
+ '/_karma_webpack_/styles.bundle.js' ,
185
+ '/_karma_webpack_/vendor.bundle.js' ,
186
+ ] ;
187
+ if ( alwaysServe . indexOf ( req . url ) != - 1 ) {
188
+ res . statusCode = 200 ;
189
+ res . end ( ) ;
190
+ } else {
191
+ res . statusCode = 404 ;
192
+ res . end ( 'Not found' ) ;
193
+ }
173
194
} ) ;
174
195
}
175
196
} ) ;
0 commit comments