diff --git a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts index 6731f97..a160f83 100644 --- a/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts +++ b/src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts @@ -23,6 +23,7 @@ interface CreateDevServerOptions { hotModuleReplacementEndpointUrl: string; } +type EsModuleExports = { __esModule: true, default: T }; type StringMap = [(key: string) => T]; // 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[]; interface WebpackConfigFunc { (env?: any): WebpackConfigOrArray; } -type WebpackConfigFileExport = WebpackConfigOrArray | WebpackConfigFunc; +type WebpackConfigExport = WebpackConfigOrArray | WebpackConfigFunc; +type WebpackConfigModuleExports = WebpackConfigExport | EsModuleExports; function attachWebpackDevMiddleware(app: any, webpackConfig: webpack.Configuration, enableHotModuleReplacement: boolean, enableReactHotModuleReplacement: boolean, hmrClientOptions: StringMap, hmrServerEndpoint: string) { // Build the final Webpack config based on supplied options @@ -235,7 +237,11 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option } // Read the webpack config's export, and normalize it into the more general 'array of configs' format - let webpackConfigExport: WebpackConfigFileExport = requireNewCopy(options.webpackConfigPath); + const webpackConfigModuleExports: WebpackConfigModuleExports = requireNewCopy(options.webpackConfigPath); + let webpackConfigExport = (webpackConfigModuleExports as EsModuleExports<{}>).__esModule === true + ? (webpackConfigModuleExports as EsModuleExports).default + : (webpackConfigModuleExports as WebpackConfigExport); + if (webpackConfigExport instanceof Function) { // If you export a function, we'll call it with an undefined 'env' arg, since we have nothing else // to pass. This is the same as what the webpack CLI tool does if you specify no '--env.x' values.