Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(node): add support for async webpack configuration #9641

Merged
merged 1 commit into from Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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