question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack code splitting with dynamically imported node_modules.

See original GitHub issue

Is your feature request related to a problem? Please describe. Dynamically imported components from ‘node_modules’ are not splitted from chunk vendor. We could use remove from ‘vendor’ property in quasar.conf.js but i found a better way to do that.

Describe the solution you’d like The issue comes from the current splitChunks config. optimization.splitChunks.cacheGroups.vendors.name is set to “vendor”, the webpack docs actually have a warning about that.

When assigning equal names to different split chunks, all vendor modules are placed into a single shared chunk, though it’s not recommend since it can result in more code downloaded.

Describe alternatives you’ve considered There is two solutions that i can think of.

1/ Set name to false/true resulting in vendor chunk named like this “vendors~app.[hash].js” and dynamically imported node_modules in separate chunks like expected.

2/ If we want to keep the vendor chunk named “vendor.[hash].js” we could use a function like this:

(_module, chunks) => {
  const allChunksNames = chunks.map((item) => item.name).join('~')
  if (allChunksNames) return 'vendor'
  else return !ctx.prod
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
freddy38510commented, Dec 12, 2019

Same results with latest v1.4

The component i try to remove from vendor chunk is a Quasar component (QTable). I dynamically import it like this:

export default {
  components: {
    QTable: () => import('quasar/src/components/table/QTable'),
  }
}

This component is lazy hydrated with a forked version of mine of vue-lazy-hydration. The fork is just an adaptation for spa prerendering.

// quasar.conf.js

vendor: {
  remove: ['quasar/src/components/table/QTable']
}

This resulting in:

webpack analyze

With remove: ['quasar/src/components/table']:

webpack analyze 2

Without quasar.conf.js -> vendor and optimization.splitChunks.cacheGroups.vendors.name set to false:

webpack analyze 3

All of this built with latest version of Quasar/app Pkg quasar........ v1.5.9 Pkg @quasar/app... v1.4.0

0reactions
rstoenescucommented, Dec 17, 2019

The new flag will be available in “@quasar/app” v1.4.2.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code Splitting - webpack
Two similar techniques are supported by webpack when it comes to dynamic code splitting. The first and recommended approach is to use the...
Read more >
Code splitting in webpack with dynamic imports - Medium
Importing files via the import() function call returns a promise and hence when webpack comes across such statements during its build process, ...
Read more >
How do I make webpack automatically chunk dynamic imports ...
I am importing a npm dependency using a dynamic import call like this const { default: Sortable } = await import( /* webpackMode:...
Read more >
Webpack From Zero to Hero. Chapter 4: Dynamic Imports and ...
Webpack supports it (of course with some differences, same as with the official static import) and adds a nice behavior to it: code...
Read more >
Code splitting with webpack and TypeScript - Spencer Miskoviak
This allows imports to be executed dynamically to lazy load modules. However, for code splitting to work with webpack these dynamic imports must ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found