Skip to content

Commit

Permalink
feat(node): add support for async webpack configuration (#9641)
Browse files Browse the repository at this point in the history
  • Loading branch information
exocom committed Apr 1, 2022
1 parent 10ae4c1 commit f922381
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
14 changes: 14 additions & 0 deletions docs/shared/guides/customize-webpack.md
Expand Up @@ -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.
Expand Down
15 changes: 9 additions & 6 deletions packages/node/src/executors/webpack/webpack.impl.ts
Expand Up @@ -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(
Expand Down

1 comment on commit f922381

@vercel
Copy link

@vercel vercel bot commented on f922381 Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.