@@ -23,6 +23,7 @@ interface CreateDevServerOptions {
2323 hotModuleReplacementEndpointUrl : string ;
2424}
2525
26+ type EsModuleExports < T > = { __esModule : true , default : T } ;
2627type StringMap < T > = [ ( key : string ) => T ] ;
2728
2829// These are the options configured in C# and then JSON-serialized, hence the C#-style naming
@@ -39,7 +40,8 @@ type WebpackConfigOrArray = webpack.Configuration | webpack.Configuration[];
3940interface WebpackConfigFunc {
4041 ( env ?: any ) : WebpackConfigOrArray ;
4142}
42- type WebpackConfigFileExport = WebpackConfigOrArray | WebpackConfigFunc ;
43+ type WebpackConfigExport = WebpackConfigOrArray | WebpackConfigFunc ;
44+ type WebpackConfigModuleExports = WebpackConfigExport | EsModuleExports < WebpackConfigExport > ;
4345
4446function attachWebpackDevMiddleware ( app : any , webpackConfig : webpack . Configuration , enableHotModuleReplacement : boolean , enableReactHotModuleReplacement : boolean , hmrClientOptions : StringMap < string > , hmrServerEndpoint : string ) {
4547 // Build the final Webpack config based on supplied options
@@ -235,7 +237,11 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
235237 }
236238
237239 // Read the webpack config's export, and normalize it into the more general 'array of configs' format
238- let webpackConfigExport : WebpackConfigFileExport = requireNewCopy ( options . webpackConfigPath ) ;
240+ const webpackConfigModuleExports : WebpackConfigModuleExports = requireNewCopy ( options . webpackConfigPath ) ;
241+ let webpackConfigExport = ( webpackConfigModuleExports as EsModuleExports < { } > ) . __esModule === true
242+ ? ( webpackConfigModuleExports as EsModuleExports < WebpackConfigExport > ) . default
243+ : ( webpackConfigModuleExports as WebpackConfigExport ) ;
244+
239245 if ( webpackConfigExport instanceof Function ) {
240246 // If you export a function, we'll call it with an undefined 'env' arg, since we have nothing else
241247 // to pass. This is the same as what the webpack CLI tool does if you specify no '--env.x' values.
0 commit comments