From f9223817b30f503c7b56a69a85f7518a1a98f98b Mon Sep 17 00:00:00 2001 From: Kalarrs Topham Date: Fri, 1 Apr 2022 15:48:31 -0700 Subject: [PATCH] feat(node): add support for async webpack configuration (#9641) --- docs/shared/guides/customize-webpack.md | 14 ++++++++++++++ .../node/src/executors/webpack/webpack.impl.ts | 15 +++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/docs/shared/guides/customize-webpack.md b/docs/shared/guides/customize-webpack.md index e8b6c3d0ea0b5..607e3357d4286 100644 --- a/docs/shared/guides/customize-webpack.md +++ b/docs/shared/guides/customize-webpack.md @@ -21,6 +21,20 @@ module.exports = (config, context) => { }; ``` +Also supports promises + +```typescript +// Utility function for sleeping +const sleep = (n) => new Promise((resolve) => setTimeout(resolve, n)); + +module.exports = async (config, context) => { + await sleep(10); + return merge(config, { + // overwrite values here + }); +}; +``` + ## Add a Loader To add the `css-loader` to your config, install it and add the rule. diff --git a/packages/node/src/executors/webpack/webpack.impl.ts b/packages/node/src/executors/webpack/webpack.impl.ts index 6d50f450e5438..de91f2204b9d7 100644 --- a/packages/node/src/executors/webpack/webpack.impl.ts +++ b/packages/node/src/executors/webpack/webpack.impl.ts @@ -81,12 +81,15 @@ export async function* webpackExecutor( if (options.generatePackageJson) { generatePackageJson(context.projectName, projGraph, options); } - const config = options.webpackConfig.reduce((currentConfig, plugin) => { - return require(plugin)(currentConfig, { - options, - configuration: context.configurationName, - }); - }, getNodeWebpackConfig(options)); + const config = await options.webpackConfig.reduce( + async (currentConfig, plugin) => { + return require(plugin)(await currentConfig, { + options, + configuration: context.configurationName, + }); + }, + Promise.resolve(getNodeWebpackConfig(options)) + ); return yield* eachValueFrom( runWebpack(config).pipe(