@@ -29,6 +29,14 @@ interface DevServerOptions {
2929 ReactHotModuleReplacement : boolean ;
3030}
3131
32+ // We support these three kinds of webpack.config.js export. We don't currently support exported promises
33+ // (though we might be able to add that in the future, if there's a need).
34+ type WebpackConfigOrArray = webpack . Configuration | webpack . Configuration [ ] ;
35+ interface WebpackConfigFunc {
36+ ( env ?: any ) : WebpackConfigOrArray ;
37+ }
38+ type WebpackConfigFileExport = WebpackConfigOrArray | WebpackConfigFunc ;
39+
3240function attachWebpackDevMiddleware ( app : any , webpackConfig : webpack . Configuration , enableHotModuleReplacement : boolean , enableReactHotModuleReplacement : boolean , hmrClientEndpoint : string , hmrServerEndpoint : string ) {
3341 // Build the final Webpack config based on supplied options
3442 if ( enableHotModuleReplacement ) {
@@ -165,10 +173,16 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
165173 const options : CreateDevServerOptions = JSON . parse ( optionsJson ) ;
166174
167175 // Read the webpack config's export, and normalize it into the more general 'array of configs' format
168- let webpackConfigArray : webpack . Configuration [ ] = requireNewCopy ( options . webpackConfigPath ) ;
169- if ( ! ( webpackConfigArray instanceof Array ) ) {
170- webpackConfigArray = [ webpackConfigArray as webpack . Configuration ] ;
176+ let webpackConfigExport : WebpackConfigFileExport = requireNewCopy ( options . webpackConfigPath ) ;
177+ if ( webpackConfigExport instanceof Function ) {
178+ // If you export a function, we'll call it with an undefined 'env' arg, since we have nothing else
179+ // to pass. This is the same as what the webpack CLI tool does if you specify no '--env.x' values.
180+ // In the future, we could add support for configuring the 'env' param in Startup.cs. But right
181+ // now, it's not clear that people will want to do that (and they can always make up their own
182+ // default env values in their webpack.config.js).
183+ webpackConfigExport = webpackConfigExport ( ) ;
171184 }
185+ const webpackConfigArray = webpackConfigExport instanceof Array ? webpackConfigExport : [ webpackConfigExport ] ;
172186
173187 const enableHotModuleReplacement = options . suppliedOptions . HotModuleReplacement ;
174188 const enableReactHotModuleReplacement = options . suppliedOptions . ReactHotModuleReplacement ;
0 commit comments