Skip to content

Conversation

JSerFeng
Copy link

@JSerFeng JSerFeng commented Oct 16, 2025

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

  • Tests updated (or not required).
  • Documentation updated (or not required).

@Copilot Copilot AI review requested due to automatic review settings October 16, 2025 03:09
Copy link
Contributor

@Copilot Copilot AI left a 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.

Copy link

netlify bot commented Oct 16, 2025

Deploy Preview for rslib ready!

Name Link
🔨 Latest commit a08d30c
🔍 Latest deploy log https://app.netlify.com/projects/rslib/deploys/68f0df00020c30000802f381
😎 Deploy Preview https://deploy-preview-1273--rslib.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

output: {
distPath: './dist/esm',
},
experiments: {
Copy link
Contributor

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
Copy link
Contributor

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.

@Timeless0911 Timeless0911 marked this pull request as draft October 16, 2025 03:46
expect(entries.esm).toMatchInlineSnapshot(`
"import node_path from "node:path";
const { join } = node_path;
const { join: join } = node_path;
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants