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

QUESTION: route based package chunking #4

Open
ahmetkuslular opened this issue Oct 18, 2023 · 2 comments
Open

QUESTION: route based package chunking #4

ahmetkuslular opened this issue Oct 18, 2023 · 2 comments

Comments

@ahmetkuslular
Copy link

hi,

The project is great, and I want to thank you first.

I'm working on a performance-focused project, and I want to chunk and separate route-based packages.

vendor: {
          test: /[\\/]node_modules[\\/]/,
          enforce: true,
          chunks: 'all',
          name(module: any) {
            const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];

            switch (packageName) {
              case 'react':
              case 'react-dom':
              case 'scheduler':
              case 'object-assign':
                return 'react';
              case 'path-to-regexp':
              case 'uuid':
                return 'rarely';
              default:
                return 'vendor';
            }
          },
        },

I want to separate them like the structure here, such as homeVendor, usersVendor, etc., and load only that vendor on the relevant page. Separating them is not a problem, but how can I decide which vendor to load on which route? Is it possible to do something like this?

@ahmetkuslular ahmetkuslular changed the title QUESTION: route based package chunking QUESTION: route based package vendor Oct 18, 2023
@ahmetkuslular ahmetkuslular changed the title QUESTION: route based package vendor QUESTION: route based package chunking Oct 18, 2023
@artem-malko
Copy link
Owner

artem-malko commented Oct 19, 2023

Hi)

You have to understand, that there is no way back if you'll start to work with code splitting in a such way) I mean such manual control.

how can I decide which vendor to load on which route

In my opinion, it's better to delegate this job to webpack or something. Cause it's highly possible, that you can break something or forget to load something important in such manual way.

In that project there is a webpack plugin: https://github.com/artem-malko/react-ssr-template/blob/main/webpack/plugins/dependencyManager/plugin.ts But this plugin can help you to have control over dynamic imports only. And it has some bugs) I'll try to fix it asap) But who knows, may be you will find something useful from it)

By the way, you said, that

Separating them is not a problem

How did you do that?)

@artem-malko
Copy link
Owner

@ahmetkuslular my plugin is ok, no bugs) I've fixed it already =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants