From 4d10b4e42cdcc94af607a4fa16ac06207a38cb73 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 21 Oct 2025 21:52:41 +0800 Subject: [PATCH 1/3] docs: update `output.module` for web target --- website/docs/en/config/output/module.mdx | 33 +++++++++++++++++++----- website/docs/zh/config/output/module.mdx | 33 +++++++++++++++++++----- 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/website/docs/en/config/output/module.mdx b/website/docs/en/config/output/module.mdx index 9b51003f74..e07fa36896 100644 --- a/website/docs/en/config/output/module.mdx +++ b/website/docs/en/config/output/module.mdx @@ -7,14 +7,32 @@ Whether to output JavaScript files in ES modules format. :::tip -- This feature is currently experimental and only available when [output.target](/config/output/target) is `'node'`. +- This feature is currently experimental and only available when [output.target](/config/output/target) is `'web'` or `'node'`. - If you need to build JavaScript libraries in ESM format, we recommend using [Rslib](https://rslib.rs), which is an out-of-the-box library development tool built on top of Rsbuild. ::: -## Example +## Web applications -When building Node.js bundles, Rsbuild outputs CommonJS format by default. You can set `output.module` to `true` to output ES modules format: +When building a web application, Rsbuild generates the output in the IIFE format by default. + +If you want to output ES Modules instead, set `output.module` to `true`: + +```ts title="rsbuild.config.ts" +export default { + output: { + module: true, + }, +}; +``` + +:::tip +When `output.module` is enabled, Rsbuild automatically adds `type="module"` to the generated `