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.

Prevent it from generating shared internal modules and bundling unused dependences from another entry point altogether

See original GitHub issue

Clear and concise description of the problem

For example, with configuration below:

build: {
    rollupOptions: {
      input: {
        main: path.resolve(__dirname, 'src/main.ts'),
        admin: path.resolve(__dirname, 'src/admin/main.ts'),
      },
    },
  },

It builds with manifest.json as below:

image

Suggested solution

The _Image.js is a component used in both entry, but it’s an internal component, it should be bundled in to admain.js and main.js. The _vendor.js includes all dependences in both entry, but not all of them was actually used in that particular entry, there should be a separation of vendors for each entry, I mean just like admin.vendor.js, main.vendor.js

Alternative

No response

Additional context

No response

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mfpopacommented, Jul 14, 2021

I am having this problem as well. If I specify build.rollupOptions.input: { ... } then modules that are shared between the input/entry files get bundled into a separate chunk. The chunk is named after one of the shared modules (a React component), e.g. Header.954792bd.js.

I don’t understand why this happens and how to change the behaviour. I could find nothing in the Vite and the Rollup documentation.

0reactions
bluwycommented, Mar 13, 2022

The _Image.js is a component used in both entry, but it’s an internal component, it should be bundled in to admain.js and main.js. The _vendor.js includes all dependences in both entry, but not all of them was actually used in that particular entry, there should be a separation of vendors for each entry, I mean just like admin.vendor.js, main.vendor.js

You can configure how the entry/chunk is created using rollupOptions.output. The output you see is Vite’s default bundling method with a vendor chunk (e.g. _vendor.js) for node_modules, and source-code (e.g. _Image.js) being code-splitted with Rollup. Re “not all of them was actually used” for the vendor chunk, this strategy is changed in Vite 2.9, so you should see finer-grain chunking for it.

Since Vite can only decide on one default chunking strategy for everyone, it’s expected for the user to configure rollupOptions if you need something specific. Closing the issue with the explanation above.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get Webpack not to bundle files - Stack Overflow
Webpack's sole purpose is to do bundling; are you sure you don't want any bundling, or do you just want some things to...
Read more >
JavaScript Modules Part 2: Module Bundling - freeCodeCamp
On a high level, module bundling is simply the process of stitching together a group of modules (and their dependencies) into a single...
Read more >
The Complete JavaScript Module Bundlers Guide - Snipcart
This in-depth guide will help you understand what you need to know about JavaScript module bundlers. A list of the top 5 best...
Read more >
rollup.js
These commands assume the entry point to your application is named main.js , and that you'd like all imports compiled into a single...
Read more >
Dependency Pre-Bundling - Vite
CommonJS and UMD compatibility: During development, Vite's dev serves all code as native ESM. · Performance: Vite converts ESM dependencies with many internal...
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