-
-
Notifications
You must be signed in to change notification settings - Fork 53
feat: using rspack EsmLibraryPlugin for better esm output #1273
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces experimental support for better ESM output using Rspack's EsmLibraryPlugin
and adds module type detection for TypeScript files. The changes enable a new experiments.advancedEsm
configuration option that generates more static-analysis-friendly ESM output with code splitting support, while also implementing automatic detection of module types based on file extensions (.mts, .cts) and package.json type fields.
Key changes:
- Added
experiments.advancedEsm
configuration option for enhanced ESM output format - Implemented module type detection for .mts (ESM) and .cts (CommonJS) file extensions
- Updated test snapshots to reflect the new ESM output format with runtime chunks
Reviewed Changes
Copilot reviewed 50 out of 52 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
website/docs/*/config/lib/experiments.mdx | Added documentation for the new experiments.advancedEsm configuration option |
website/docs/*/config/lib/_meta.json | Added experiments to documentation navigation |
tests/scripts/shared.ts | Updated generateBundleEsmConfig to enable advancedEsm by default |
tests/package.json | Reverted dependency version changes |
tests/integration/**/index.test.ts | Updated test snapshots to match new ESM output format |
tests/integration/package-json/** | Added test fixtures for package.json type field detection |
packages/core/src/types/config.ts | Added LibExperiments type definition with advancedEsm option |
packages/core/src/config.ts | Implemented EsmLibraryPlugin integration and module type detection logic |
examples/**/rslib.config.ts | Enabled advancedEsm in example configurations |
packages/plugin-dts/package.json | Reverted version changes |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
✅ Deploy Preview for rslib ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
output: { | ||
distPath: './dist/esm', | ||
}, | ||
experiments: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fi3ework I think we should still preserve tests with modern-module esm. Maybe we should refactor the tests, not sure about the workload.
@@ -0,0 +1,28 @@ | |||
# lib.experiments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can link this chapter in https://rslib.rs/config/lib/format.
expect(entries.esm).toMatchInlineSnapshot(` | ||
"import node_path from "node:path"; | ||
const { join } = node_path; | ||
const { join: join } = node_path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why, I'm looking into it
Summary
Using EsmLibraryPlugin for better ESM output
Now you can use
experiments.advancedEsm
to enable new esm format.Compared to the previous, this supports split chunk, and every single output chunk can easily statically analyzed if scope hoisted. Not use rspack runtime to load chunks anymore
Related Links
Checklist