@@ -29,6 +29,14 @@ interface DevServerOptions {
29
29
ReactHotModuleReplacement : boolean ;
30
30
}
31
31
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
+
32
40
function attachWebpackDevMiddleware ( app : any , webpackConfig : webpack . Configuration , enableHotModuleReplacement : boolean , enableReactHotModuleReplacement : boolean , hmrClientEndpoint : string , hmrServerEndpoint : string ) {
33
41
// Build the final Webpack config based on supplied options
34
42
if ( enableHotModuleReplacement ) {
@@ -165,10 +173,16 @@ export function createWebpackDevServer(callback: CreateDevServerCallback, option
165
173
const options : CreateDevServerOptions = JSON . parse ( optionsJson ) ;
166
174
167
175
// 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 ( ) ;
171
184
}
185
+ const webpackConfigArray = webpackConfigExport instanceof Array ? webpackConfigExport : [ webpackConfigExport ] ;
172
186
173
187
const enableHotModuleReplacement = options . suppliedOptions . HotModuleReplacement ;
174
188
const enableReactHotModuleReplacement = options . suppliedOptions . ReactHotModuleReplacement ;
0 commit comments