Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Webpack node module getting added in multiple chunks in my react application #18408

Closed
VishalGulati opened this issue May 17, 2024 · 0 comments
Closed

Comments

@VishalGulati
Copy link

VishalGulati commented May 17, 2024

In my react application, I am using react-addons-css-transition-group node module. In the prod build, webpack (5.36.2) is clubbing this module in multiple chunks and not with the vendor even though I have defined vendor splitChunks cacheGroup config as node_modules folder.

vendor: /[\\/]node_modules[\\/]/,

splitChunks: {
  name: false,
  cacheGroups: {
    commons:  {
      test: {
        vendor: /[\\/]node_modules[\\/]/,
      },
      name: 'vendor',
      chunks: 'initial'
    },
    default: {
      minChunks: 2,
      reuseExistingChunk: true,
      minSize: 100000
    }
  }
}

My question is why isn't webpack making a single chunk for this module so it can be loaded in all pages making use of it?

Also sometimes it clubs this module with components that are not needed in a particular page but get loaded through the chunk because of the node module. How should we deal with this?

PS: my vendor is 86kB gzip currently and some npm modules are clubbed in other chunks with my source code. My problem is not specific to react-addons-css-transition-group. Its happening for lot of other modules too.

Bug report

What is the current behavior?

It is not adding a node module in one chunk only and replicating in multiple? Sometimes it clubs it with code that is only required in page B lets say but gets loaded in page A because of reference to the node module.

What is the expected behavior?

Ideally webpack should put all node modules in vendor bundle as specified in config. But since its not putting every node module there I suspect it might be due to already heavy size of vendor 86kb GZIP and hence remaining node modules are being clubbed in other chunks. But chunking is not logical as it should prevent clubbing modules with source code that is specific to a particular page and could accidentally ship to other pages too due to this.

Other relevant information:
webpack version: 5.36.2
Node.js version: 12.18.3
Operating System: Mac OS
Additional tools:

@webpack webpack locked and limited conversation to collaborators May 22, 2024
@alexander-akait alexander-akait converted this issue into discussion #18424 May 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant