From 2db6f89d04835e94ac09361ada35cf9b87fbab9b Mon Sep 17 00:00:00 2001 From: Artur Androsovych Date: Sat, 25 Sep 2021 01:19:14 +0300 Subject: [PATCH] feat(angular): allow exporting function and promise within the custom Webpack config (#7129) --- .../webpack-server/webpack-server.impl.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/angular/src/builders/webpack-server/webpack-server.impl.ts b/packages/angular/src/builders/webpack-server/webpack-server.impl.ts index 0aceb7824a..674506eb2e 100644 --- a/packages/angular/src/builders/webpack-server/webpack-server.impl.ts +++ b/packages/angular/src/builders/webpack-server/webpack-server.impl.ts @@ -42,9 +42,21 @@ export function webpackServer(schema: Schema, context: BuilderContext) { if (existsSync(pathToWebpackConfig)) { return serveWebpackBrowser(options as DevServerBuilderOptions, context, { - webpackConfiguration: (baseWebpackConfig) => { + webpackConfiguration: async (baseWebpackConfig) => { 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 {