feat(angular): allow exporting function and promise within the custom Webpack config (#7129)

This commit is contained in:
Artur Androsovych 2021-09-25 01:19:14 +03:00 committed by GitHub
parent 18e369c85c
commit 2db6f89d04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,9 +42,21 @@ export function webpackServer(schema: Schema, context: BuilderContext) {
if (existsSync(pathToWebpackConfig)) { if (existsSync(pathToWebpackConfig)) {
return serveWebpackBrowser(options as DevServerBuilderOptions, context, { return serveWebpackBrowser(options as DevServerBuilderOptions, context, {
webpackConfiguration: (baseWebpackConfig) => { webpackConfiguration: async (baseWebpackConfig) => {
const customWebpackConfiguration = require(pathToWebpackConfig); const customWebpackConfiguration = require(pathToWebpackConfig);
return merge(baseWebpackConfig, customWebpackConfiguration); // The extra Webpack configuration file can export a synchronous or asynchronous function,
// for instance: `module.exports = async config => { ... }`.
if (typeof customWebpackConfiguration === 'function') {
return customWebpackConfiguration(baseWebpackConfig);
} else {
return merge(
baseWebpackConfig,
// The extra Webpack configuration file can also export a Promise, for instance:
// `module.exports = new Promise(...)`. If it exports a single object, but not a Promise,
// then await will just resolve that object.
await customWebpackConfiguration
);
}
}, },
}); });
} else { } else {