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

Feature Request: Merge small chunks into one chuck; having a capability to configure #3828

Open
dipu7388 opened this issue Jul 10, 2024 · 1 comment

Comments

@dipu7388
Copy link

Description

Currently, when exporting constants or any file which a multiple exports in our project, each export generates a separate chunk during the build process. For example, a file like global.constants.ts with exports such as:

export const A = 0;
export const B = 1;
export const C = 2;
results in three separate chunks being generated.

Requested Feature
We would like to request a feature that allows us to merge these separate chunks into a single chunk during the build process. This capability would help in reducing the number of HTTP requests and improving loading times by bundling related exports into a single chunk.


### Steps to Reproduce
1. Clone the repository with the specific branch:
   ```bash
   git clone -b native-federation https://github.com/dipu7388/multiple-entry.git
   cd multiple-entry
@dipu7388 dipu7388 changed the title Feature Request: Merge Shared Bundles into One Feature Request: Merge small chunks into one chuck; having a capability to configure Jul 10, 2024
@hyrious
Copy link

hyrious commented Jul 11, 2024

Merging chunks is supported by Rollup, however this is not always safe to do so. For example:

// shared.js
export let util = 1

// a.js (entry)
import { util } from './shared.js'
import b from './b.js'
foo(b, util)

// b.js (entry)
import { util } from './shared.js'
export default bar(util)

If merging shared into a, the result may look like:

// dist/a.js (a   shared)
export let util = 1
import b from './b.js' // a -> b
foo(b, util)

// dist/b.js (b)
import { util } from './a.js' // b -> a
export default bar(util)

…which seems ok on a quick look. However it causes different behavior from the original code: b doesn't depend on a, running node b.js only executes bar(...). However dist/b depends on dist/a and running node dist/b.js executes bar(...) then foo(...).

On the other hand, chunk splitting is also not very safe since common chunks may be executed in unwanted order. 🤷

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