@@ -23,6 +23,7 @@ interface CreateDevServerOptions {
23
23
hotModuleReplacementEndpointUrl : string ;
24
24
}
25
25
26
+ type EsModuleExports < T > = { __esModule : true , default : T } ;
26
27
type StringMap < T > = [ ( key : string ) => T ] ;
27
28
28
29
// 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[];
39
40
interface WebpackConfigFunc {
40
41
( env ?: any ) : WebpackConfigOrArray ;
41
42
}
42
- type WebpackConfigFileExport = WebpackConfigOrArray | WebpackConfigFunc ;
43
+ type WebpackConfigExport = WebpackConfigOrArray | WebpackConfigFunc ;
44
+ type WebpackConfigModuleExports = WebpackConfigExport | EsModuleExports < WebpackConfigExport > ;
43
45
44
46
function attachWebpackDevMiddleware ( app : any , webpackConfig : webpack . Configuration , enableHotModuleReplacement : boolean , enableReactHotModuleReplacement : boolean , hmrClientOptions : StringMap < string > , hmrServerEndpoint : string ) {
45
47
// Build the final Webpack config based on supplied options
@@ -235,7 +237,11 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
235
237
}
236
238
237
239
// 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
+
239
245
if ( webpackConfigExport instanceof Function ) {
240
246
// If you export a function, we'll call it with an undefined 'env' arg, since we have nothing else
241
247
// to pass. This is the same as what the webpack CLI tool does if you specify no '--env.x' values.
0 commit comments