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

feat: code splitting base on directives #305

Merged
merged 4 commits into from
Dec 17, 2023
Merged

feat: code splitting base on directives #305

merged 4 commits into from
Dec 17, 2023

Conversation

huozhi
Copy link
Owner

@huozhi huozhi commented Dec 17, 2023

Split module with "use client" and "use server" directives into different chunks, so that bundler can the boundaries are controlled as minimum size. When they're integrated to the app like Next.js, the bundler can analyze the boundaries properly and transform into properly client components or server actions modules

@huozhi huozhi changed the title feat code splitting base on directives feat: code splitting base on directives Dec 17, 2023
@huozhi huozhi marked this pull request as ready for review December 17, 2023 18:15
@huozhi huozhi merged commit d448810 into main Dec 17, 2023
3 checks passed
@huozhi huozhi deleted the code-splitting branch December 17, 2023 18:15
@lovrozagar
Copy link

When using bunchee -m, minification removes the directive at the top of the file, components with "use client", after building, become server components even though they are separated into a x-client.js file. Works fine when using just bunchee without minification.

@nnecec
Copy link
Contributor

nnecec commented Feb 23, 2024

What does the prependDirectives plugin do? It looks like the rollup-preserve-directives plugin collects directives and prepends directives at the render phase.

According to the rollup-plugin-swc3 documentation, rollup-preserve-directives should be used after swc3, it'll fix the -m problem.

@huozhi
Copy link
Owner Author

huozhi commented Mar 3, 2024

@nnecec if the module is marked as certain type, we need to append the directive, that's what prependDirectives is doing.
We can carry on the discussion in #462

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

Successfully merging this pull request may close these issues.

3 participants