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

fix(webpack): enable in memory caching when building for node in watch mode #18348

Merged

Conversation

mattlewis92
Copy link
Contributor

Current Behavior

Using @nx/webpack for building node apps in watch mode is slow.

After checking all nx versions we found the root cause was this PR: #16625

Setting mode: 'none' has the side effect of disabling webpack's in memory caching:
https://github.com/webpack/webpack/blob/main/lib/config/defaults.js#L198-L200

Which in turn makes incremental rebuilds with large node apps have poor performance due to webpack re-compiling every file on change instead of just the affected files.

Expected Behavior

Using @nx/webpack for building node apps in watch mode is fast

Related Issue(s)

N/A

@mattlewis92 mattlewis92 requested a review from a team as a code owner July 27, 2023 17:04
@mattlewis92 mattlewis92 requested a review from jaysoo July 27, 2023 17:04
@vercel
Copy link

vercel bot commented Jul 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 27, 2023 5:27pm

@mattlewis92 mattlewis92 changed the title perf(webpack): enable in memory caching when building for node in watch mode fix(webpack): enable in memory caching when building for node in watch mode Jul 27, 2023
@mattlewis92 mattlewis92 force-pushed the matt/webpack-node-rebuild-perf branch from 5c90acb to 888fc91 Compare July 27, 2023 17:17
@andrey59412678
Copy link

andrey59412678 commented Aug 6, 2023

Thank you so much for this. This was the single thing that was preventing me to upgrade to Nx 16, it was annoying to work on such a slow rebuild (more than 5 seconds for every code change).

Adding cache = true to my projects webpack.config.js solved the problem. Now the live reload is just as fast as it was on Nx 15, almost instant.

const { composePlugins, withNx } = require('@nx/webpack');

module.exports = composePlugins(withNx(), (config) => {
  config.cache = true;
  return config;
});

Pretty sure this is related to #17070

@mattlewis92
Copy link
Contributor Author

@jaysoo any chance you could take a look at this fix please? 😄

Copy link
Contributor

@ndcunningham ndcunningham left a comment

Choose a reason for hiding this comment

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

LGTM

@ndcunningham ndcunningham merged commit f30174b into nrwl:master Sep 6, 2023
15 checks passed
FrozenPandaz pushed a commit that referenced this pull request Sep 7, 2023
@github-actions
Copy link

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants