|
| 1 | +import { RsbuildDocBadge } from '@components/RsbuildDocBadge'; |
| 2 | + |
1 | 3 | # output |
| 4 | + |
| 5 | +与构建产物相关的选项。 |
| 6 | + |
| 7 | +## output.charset <RsbuildDocBadge path="/config/output/charset" text="output.charset" /> |
| 8 | + |
| 9 | +指定输出文件的 [字符编码](https://developer.mozilla.org/en-US/docs/Glossary/Character_encoding),以确保它们在不同的环境中能够正确显示。 |
| 10 | + |
| 11 | +## output.cleanDistPath <RsbuildDocBadge path="/config/output/clean-dist-path" text="output.cleanDistPath" /> |
| 12 | + |
| 13 | +是否在构建开始前清理产物目录下的所有文件(产物目录默认为 `dist`)。 |
| 14 | + |
| 15 | +## output.copy <RsbuildDocBadge path="/config/output/copy" text="output.copy" /> |
| 16 | + |
| 17 | +将指定的文件或目录拷贝到构建输出目录中,基于 [rspack.CopyRspackPlugin](https://rspack.dev/zh/plugins/rspack/copy-rspack-plugin) 实现。 |
| 18 | + |
| 19 | +## output.cssModules <RsbuildDocBadge path="/config/output/css-modules" text="output.cssModules" /> |
| 20 | + |
| 21 | +用于自定义 CSS Modules 配置。 |
| 22 | + |
| 23 | +## output.dataUriLimit <RsbuildDocBadge path="/config/output/data-uri-limit" text="output.dataUriLimit" /> |
| 24 | + |
| 25 | +设置图片、字体、媒体等静态资源被自动内联为 base64 的体积阈值。 |
| 26 | + |
| 27 | +## output.distPath <RsbuildDocBadge path="/config/output/dist-path" text="output.distPath" /> |
| 28 | + |
| 29 | +设置构建产物的输出目录,Rsbuild 会根据产物的类型输出到对应的子目录下。 |
| 30 | + |
| 31 | +## output.emitCss <RsbuildDocBadge path="/config/output/emit-css" text="output.emitCss" /> |
| 32 | + |
| 33 | +是否将 CSS 输出到产物中。 |
| 34 | + |
| 35 | +## output.externals <RsbuildDocBadge path="/config/output/externals" text="output.externals" /> |
| 36 | + |
| 37 | +在构建时,防止将代码中某些 `import` 的依赖包打包到 bundle 中,而是在运行时再去从外部获取这些依赖。 |
| 38 | + |
| 39 | +需要注意的是,`output.externals` 与 [resolve.alias](/config/rsbuild/resolve#resolvealias) 有所不同。请查看 [resolve.alias](/config/rsbuild/resolve#resolvealias) 文档以了解更多信息。 |
| 40 | + |
| 41 | +## output.filenameHash <RsbuildDocBadge path="/config/output/filename-hash" text="output.filenameHash" /> |
| 42 | + |
| 43 | +在生产模式构建后,是否在产物的文件名中添加 hash 值。 |
| 44 | + |
| 45 | +## output.filename <RsbuildDocBadge path="/config/output/filename" text="output.filename" /> |
| 46 | + |
| 47 | +设置构建产物的名称。 |
| 48 | + |
| 49 | +## output.inlineScripts <RsbuildDocBadge path="/config/output/inline-scripts" text="output.inlineScripts" /> |
| 50 | + |
| 51 | +用来控制是否用 `<script>` 标签将产物中的 script 文件(.js 文件)inline 到 HTML 中。 |
| 52 | + |
| 53 | +## output.inlineStyles <RsbuildDocBadge path="/config/output/inline-styles" text="output.inlineStyles" /> |
| 54 | + |
| 55 | +用来控制是否用 `<style>` 标签将产物中的 style 文件(.css 文件)inline 到 HTML 中。 |
| 56 | + |
| 57 | +## output.legalComments <RsbuildDocBadge path="/config/output/legal-comments" text="output.legalComments" /> |
| 58 | + |
| 59 | +配置 legal comment 的处理方式。 |
| 60 | + |
| 61 | +## output.manifest <RsbuildDocBadge path="/config/output/manifest" text="output.manifest" /> |
| 62 | + |
| 63 | +是否生成 manifest 文件,该文件包含所有构建产物的信息、以及[入口模块](https://rsbuild.dev/zh/config/source/entry)与构建产物间的映射关系。 |
| 64 | + |
| 65 | +## output.minify <RsbuildDocBadge path="/config/output/minify" text="output.minify" /> |
| 66 | + |
| 67 | +用于设置是否在生产模式下开启代码压缩,或是配置压缩工具的选项。 |
| 68 | + |
| 69 | +## output.overrideBrowserslist <RsbuildDocBadge path="/config/output/override-browserslist" text="output.overrideBrowserslist" /> |
| 70 | + |
| 71 | +指定项目兼容的目标浏览器范围。 |
| 72 | + |
| 73 | +## output.polyfill <RsbuildDocBadge path="/config/output/polyfill" text="output.polyfill" /> |
| 74 | + |
| 75 | +控制 polyfills 的注入方式。 |
| 76 | + |
| 77 | +:::warning |
| 78 | +Rsbuild 的 `output.polyfill` 会将 polyfills 注入到全局作用域中,这可能会意外地修改库消费者的全局变量。对于非全局的 polyfill 方案,请参考 [Polyfill - 浏览器](/guide/advanced/output-compatibility#浏览器)。 |
| 79 | +::: |
| 80 | + |
| 81 | +## output.sourceMap <RsbuildDocBadge path="/config/output/source-map" text="output.sourceMap" /> |
| 82 | + |
| 83 | +用于设置是否生成 source map 文件,以及生成哪一种格式的 source map。 |
| 84 | + |
| 85 | +## output.target <RsbuildDocBadge path="/config/output/target" text="output.target" /> |
| 86 | + |
| 87 | +用于设置 Rsbuild 的构建产物类型。 |
| 88 | + |
| 89 | +:::info |
| 90 | +请查看 [解决方案](/guide/solution/) 了解更多关于构建产物的信息。 |
| 91 | +::: |
0 commit comments