Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 08002e9

Browse files
In WebpackDevMiddleware.ts, support loading Webpack config files with __esModule. Fixes #1378
1 parent 0c77224 commit 08002e9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Microsoft.AspNetCore.SpaServices/npm/aspnet-webpack/src/WebpackDevMiddleware.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface CreateDevServerOptions {
2323
hotModuleReplacementEndpointUrl: string;
2424
}
2525

26+
type EsModuleExports<T> = { __esModule: true, default: T };
2627
type 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[];
3940
interface WebpackConfigFunc {
4041
(env?: any): WebpackConfigOrArray;
4142
}
42-
type WebpackConfigFileExport = WebpackConfigOrArray | WebpackConfigFunc;
43+
type WebpackConfigExport = WebpackConfigOrArray | WebpackConfigFunc;
44+
type WebpackConfigModuleExports = WebpackConfigExport | EsModuleExports<WebpackConfigExport>;
4345

4446
function 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

Comments
 (0)