@@ -50,17 +50,24 @@ function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configurati
50
50
}
51
51
52
52
// Now also inject eventsource polyfill so this can work on IE/Edge (unless it's already there)
53
+ // To avoid this being a breaking change for everyone who uses aspnet-webpack, we only do this if you've
54
+ // referenced event-source-polyfill in your package.json. Note that having event-source-polyfill available
55
+ // on the server in node_modules doesn't imply that you've also included it in your client-side bundle,
56
+ // but the converse is true (if it's not in node_modules, then you obviously aren't trying to use it at
57
+ // all, so it would definitely not work to take a dependency on it).
53
58
const eventSourcePolyfillEntryPoint = 'event-source-polyfill' ;
54
- const entryPointsArray : string [ ] = entryPoints [ entryPointName ] ; // We know by now that it's an array, because if it wasn't, we already wrapped it in one
55
- if ( entryPointsArray . indexOf ( eventSourcePolyfillEntryPoint ) < 0 ) {
56
- const webpackHmrIndex = firstIndexOfStringStartingWith ( entryPointsArray , webpackHotMiddlewareEntryPoint ) ;
57
- if ( webpackHmrIndex < 0 ) {
58
- // This should not be possible, since we just added it if it was missing
59
- throw new Error ( 'Cannot find ' + webpackHotMiddlewareEntryPoint + ' in entry points array: ' + entryPointsArray ) ;
60
- }
59
+ if ( npmModuleIsPresent ( eventSourcePolyfillEntryPoint ) ) {
60
+ const entryPointsArray : string [ ] = entryPoints [ entryPointName ] ; // We know by now that it's an array, because if it wasn't, we already wrapped it in one
61
+ if ( entryPointsArray . indexOf ( eventSourcePolyfillEntryPoint ) < 0 ) {
62
+ const webpackHmrIndex = firstIndexOfStringStartingWith ( entryPointsArray , webpackHotMiddlewareEntryPoint ) ;
63
+ if ( webpackHmrIndex < 0 ) {
64
+ // This should not be possible, since we just added it if it was missing
65
+ throw new Error ( 'Cannot find ' + webpackHotMiddlewareEntryPoint + ' in entry points array: ' + entryPointsArray ) ;
66
+ }
61
67
62
- // Insert the polyfill just before the HMR entrypoint
63
- entryPointsArray . splice ( webpackHmrIndex , 0 , eventSourcePolyfillEntryPoint ) ;
68
+ // Insert the polyfill just before the HMR entrypoint
69
+ entryPointsArray . splice ( webpackHmrIndex , 0 , eventSourcePolyfillEntryPoint ) ;
70
+ }
64
71
}
65
72
} ) ;
66
73
@@ -189,3 +196,12 @@ function firstIndexOfStringStartingWith(array: string[], prefixToFind: string) {
189
196
190
197
return - 1 ; // Not found
191
198
}
199
+
200
+ function npmModuleIsPresent ( moduleName : string ) {
201
+ try {
202
+ require . resolve ( moduleName ) ;
203
+ return true ;
204
+ } catch ( ex ) {
205
+ return false ;
206
+ }
207
+ }
0 commit comments