Skip to content
Merged

d2m #1461

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
094afce
feat: use rolldown to bundle config
sapphi-red Mar 7, 2025
dc2721a
chore: set `ROLLDOWN_OPTIONS_VALIDATION=loose` for vitepress
sapphi-red Mar 10, 2025
7477a78
chore: merge main
sapphi-red Apr 2, 2025
65fb861
chore: merge main
sapphi-red Apr 3, 2025
42eca8b
chore: merge main
sapphi-red Apr 10, 2025
164751c
chore: merge main
sapphi-red Apr 12, 2025
c147ae2
chore: merge main
sapphi-red Apr 17, 2025
99c880e
chore: merge main
sapphi-red Apr 18, 2025
8fd367f
chore: remove unnecessary workaround
sapphi-red Apr 21, 2025
0cfc5bb
chore: merge main
sapphi-red Apr 24, 2025
d30fc40
chore: merge main
sapphi-red Apr 30, 2025
b995b34
chore: merge main
sapphi-red May 16, 2025
612f536
chore: merge commit '86b5e0030bf204f8f2db0cf8ee895ab3ecf154b8' into r…
sapphi-red Jun 16, 2025
a0098e5
chore: merge commit 'a37ac836ac4da8e854d98c65450f12acb921aa98' into r…
sapphi-red Jun 16, 2025
b2d009a
Merge commit '61b6b96b191c6071b9c574ad4c795f97f2646f18' into rolldown…
sapphi-red Jun 16, 2025
2bc2432
chore: merge commit 'a33d0c7d65d9fff9acd5de0cf3c4d371297b3990' into r…
sapphi-red Jun 16, 2025
f6f8386
chore: merge commit '24692dbeccd148a60f563bc96e12e3609e5ba642' into r…
sapphi-red Jun 16, 2025
586ccc5
chore: merge commit '9c6cbe602187644887b0a4342de6b486c8f60f4d' into r…
sapphi-red Jun 17, 2025
946692f
chore: merge main
sapphi-red Jun 17, 2025
45e3a41
chore: merge main
sapphi-red Jun 20, 2025
f62acfd
chore: merge main
sapphi-red Jun 24, 2025
b54cd33
chore: merge main
sapphi-red Jun 25, 2025
6b5516e
chore: fix docs build
sapphi-red Jun 25, 2025
587fa33
chore: merge main
sapphi-red Jun 27, 2025
49755dc
chore: merge main
sapphi-red Jul 2, 2025
81ba548
chore: merge main
sapphi-red Jul 3, 2025
303e850
chore: remove `ROLLDOWN_OPTIONS_VALIDATION=loose` from vitepress config
sapphi-red Jul 4, 2025
5bb3903
chore: merge main
sapphi-red Jul 4, 2025
fa694cb
chore: merge main
sapphi-red Jul 8, 2025
f3c9bb9
chore: merge main
sapphi-red Jul 10, 2025
5e5645b
chore: merge main
sapphi-red Jul 18, 2025
975afc2
chore: merge main
sapphi-red Jul 25, 2025
9934f7c
chore: merge main
sapphi-red Jul 30, 2025
a119488
feat: enable native resolver by default (#346)
sapphi-red Aug 4, 2025
ef38b75
chore: merge main
sapphi-red Aug 5, 2025
850cf53
chore: merge main
sapphi-red Aug 7, 2025
73846cb
chore: merge main
sapphi-red Aug 12, 2025
6970a42
chore: merge main
sapphi-red Aug 19, 2025
040b0ca
chore: merge main
sapphi-red Aug 21, 2025
567b062
chore: merge main
sapphi-red Sep 8, 2025
50f05ec
chore: merge main
sapphi-red Sep 18, 2025
dcb4874
chore: merge main
sapphi-red Sep 22, 2025
4d772bd
chore: merge main
sapphi-red Sep 24, 2025
6976d28
chore: merge main
sapphi-red Oct 2, 2025
863e357
chore: merge main
sapphi-red Oct 3, 2025
52bdbf4
chore: merge main
sapphi-red Oct 14, 2025
b64c453
chore: merge main
sapphi-red Oct 20, 2025
024748a
feat: update rolldown (#456)
sapphi-red Oct 20, 2025
3898900
chore: merge main
sapphi-red Oct 28, 2025
88fe0a2
chore: merge main
sapphi-red Nov 4, 2025
82aafa3
feat: update rolldown (#481)
sapphi-red Nov 4, 2025
880c4e3
chore: merge main
sapphi-red Nov 5, 2025
ca48f6d
chore: merge main
sapphi-red Nov 6, 2025
d012b23
chore: merge main
sapphi-red Nov 7, 2025
220fc89
feat: update rolldown to 1.0.0-beta.50 (#508)
sapphi-red Nov 12, 2025
996709e
docs: migration guide (#469)
sapphi-red Nov 14, 2025
a5635e2
chore: merge main
sapphi-red Nov 20, 2025
f34a231
chore: merge main
sapphi-red Nov 26, 2025
b0f2c87
feat: update rolldown to 1.0.0-beta.52 (#522)
shulaoda Nov 26, 2025
e390394
chore: merge main
sapphi-red Dec 1, 2025
d3e337c
docs: update content for beta (#529)
sapphi-red Dec 2, 2025
f337511
docs: remove rolldown page (#528)
sapphi-red Dec 2, 2025
8add1ce
chore: merge main
sapphi-red Dec 2, 2025
21e1d45
docs: update migration guide. (#538)
cpojer Dec 3, 2025
bf15e07
feat: update rolldown to 1.0.0-beta.53 (#537)
shulaoda Dec 3, 2025
283a277
feat!: update default browser target (#21193)
sapphi-red Dec 3, 2025
cba1f62
docs: add `resolve.tsconfigPaths` option docs (#21197)
sapphi-red Dec 3, 2025
526217a
docs: add `emitDecoratorMetadata` description (#21198)
sapphi-red Dec 3, 2025
eedd9bc
docs: `alwaysStrict` does not affect the build result anymore (#21199)
sapphi-red Dec 3, 2025
db800be
docs: vite 8 beta announcement (#21196)
sapphi-red Dec 3, 2025
73dbb45
docs: add overrides note in vite 8 beta post (#21201)
sapphi-red Dec 3, 2025
9d1e98c
docs: update override instructions in release post (#21204)
TheAlexLichter Dec 3, 2025
e6e9263
docs(en): merging all conflicts
docschina-bot Dec 3, 2025
c64b509
docs: update content
lxKylin Dec 4, 2025
bb62f46
docs: update announcing-vite8-beta.md
lxKylin Dec 4, 2025
5ae6127
docs: update content
lxKylin Dec 4, 2025
79e5f69
Merge pull request #1457 from lxKylin/98c9-1
thinkasany Dec 4, 2025
2e25b9f
Merge pull request #1456 from vitejs/sync-9d1e98c9-1
thinkasany Dec 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,6 @@ export default defineConfig({
text: '性能',
link: '/guide/performance'
},
{
text: 'Rolldown',
link: '/guide/rolldown'
},
{
text: `Migration from v${viteMajorVersion - 1}`,
link: '/guide/migration'
Expand Down
163 changes: 163 additions & 0 deletions blog/announcing-vite8-beta.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
---
title: 'Vite 8 Beta: The Rolldown-powered Vite'
author:
name: The Vite Team
date: 2025-12-03
sidebar: false
head:
- - meta
- property: og:type
content: website
- - meta
- property: og:title
content: Announcing Vite 8 Beta
- - meta
- property: og:image
content: https://vite.dev/og-image-announcing-vite8-beta.webp
- - meta
- property: og:url
content: https://vite.dev/blog/announcing-vite8-beta
- - meta
- property: og:description
content: Vite 8 Beta Release Announcement
- - meta
- name: twitter:card
content: summary_large_image
---

# Vite 8 Beta:由 Rolldown 驱动的 Vite {#vite-8-beta}

_2025年12月3日_

![Vite 8 Beta Announcement Cover Image](/og-image-announcing-vite8-beta.webp)

摘要:由 [Rolldown](https://rolldown.rs/) 驱动的 Vite 8 首个测试版现已发布。Vite 8 提供了显著更快的生产构建速度,并开启了未来的改进可能性。你可以通过将 `vite` 升级到 `8.0.0-beta.0` 版本并阅读[迁移指南](/guide/migration)来试用这个新版本。

---

我们很高兴发布 Vite 8 的首个测试版。这个版本统一了底层工具链,带来了更好的一致性行为,以及显著的构建性能提升。Vite 现在使用 [Rolldown](https://rolldown.rs/) 作为其打包器,取代了之前 esbuild 和 Rollup 的组合。

## 面向 Web 的全新打包器 {#a-new-bundler-for-the-web}

Vite 之前依赖两个打包器来满足开发和生产构建的不同需求:

1. 开发期间使用 esbuild 进行快速编译
2. 生产构建使用 Rollup 进行打包、分块和优化

这种方法让 Vite 能够专注于开发者体验和协调,而无需重新发明解析和打包功能。然而,维护两个独立的打包流水线引入了不一致性:独立的转换流水线、不同的插件系统,以及越来越多的粘合代码来保持开发和生产之间打包行为的一致性。

为了解决这个问题,[VoidZero 团队](https://voidzero.dev) 构建了 **Rolldown**,这是一个下一代打包器,目标是在 Vite 中使用。它的设计特点包括:

- **性能**:Rolldown 使用 Rust 编写,以原生速度运行。它的性能水平与 esbuild 相匹配,并且比 Rollup [快 10-30 倍](https://github.com/rolldown/benchmarks)。
- **兼容性**:Rolldown 支持与 Rollup 和 Vite 相同的插件 API。大多数 Vite 插件在 Vite 8 中可以开箱即用。
- **更多功能**:Rolldown 为 Vite 解锁了更多高级功能,包括完整打包模式、更灵活的分块控制、模块级持久缓存、模块联邦等。

## 统一工具链 {#unifying-the-toolchain}

Vite 打包器更换的影响超越了性能范畴。打包器利用解析器、解析器、转换器和压缩器。Rolldown 为此目的使用了由 VoidZero 团队主导的另一个项目 Oxc。

**这使得 Vite 成为由同一团队维护的端到端工具链的入口:构建工具(Vite)、打包器(Rolldown)和编译器(Oxc)。**

这种一致性确保了整个堆栈中的行为一致性,并且随着 JavaScript 的不断发展,使我们能够快速采用并与新的语言规范保持一致。这也解锁了以前仅凭 Vite 无法实现的广泛改进。例如,我们可以利用 Oxc 的语义分析在 Rolldown 中实现更好的 tree-shaking。

## Vite 如何迁移到 Rolldown {#how-vite-migrated-to-rolldown}

迁移到由 Rolldown 驱动的 Vite 是一项基础性变革。因此,我们的团队采取了深思熟虑的步骤来实施这一变革,同时不牺牲稳定性和生态系统兼容性。

首先,我们发布了独立的 `rolldown-vite` 包作为[技术预览版](https://voidzero.dev/posts/announcing-rolldown-vite)。这让我们能够在不影响 Vite 稳定版本的情况下与早期采用者合作。早期采用者从 Rolldown 的性能提升中受益,同时提供了宝贵的反馈。亮点包括:

- Linear 的生产构建时间从 46 秒减少到 6 秒
- Mercedes-Benz.io 将构建时间减少了高达 38%
- Beehiiv 将构建时间减少了 64%

接下来,我们建立了一套测试套件,用于验证关键的 Vite 插件与 `rolldown-vite` 的兼容性。这项 CI 任务帮助我们及早发现回归问题和兼容性问题,特别是对于 SvelteKit、react-router 和 Storybook 等框架和元框架。

最后,我们构建了一个兼容层,帮助开发者从 Rollup 和 esbuild 选项迁移到相应的 Rolldown 选项。

因此,每个人都能顺利迁移到 Vite 8。

## 迁移到 Vite 8 Beta {#migrating-to-vite-8-beta}

由于 Vite 8 涉及核心构建行为,我们专注于保持配置 API 和插件钩子不变。我们创建了[迁移指南](/guide/migration)来帮助您升级。

有两种可用的升级路径:

1. **直接升级**:更新 `package.json` 并运行常规的开发和构建命令。
2. **渐进式迁移**:从 Vite 7 迁移到 `rolldown-vite` 包,然后再到 Vite 8。这样您可以识别出与 Rolldown 相关的不兼容性或问题,而不会对 Vite 造成其他更改。(推荐用于较大或复杂的项目)

> [!IMPORTANT]
> 如果你依赖特定的 Rollup 或 esbuild 选项,你可能需要对 Vite 配置进行一些调整。请参考[迁移指南](/guide/migration)获取详细的说明和示例。
> 与所有非稳定的主版本一样,升级后建议进行全面测试以确保一切按预期工作。请务必报告任何[问题](https://github.com/vitejs/rolldown-vite/issues)。

如果你使用的框架或工具将 Vite 作为依赖项,例如 Astro、Nuxt 或 Vitest,你必须在 `package.json` 中覆盖 `vite` 依赖项,这根据你使用的包管理器略有不同:

:::code-group

```json [npm]
{
"overrides": {
"vite": "8.0.0-beta.0"
}
}
```

```json [Yarn]
{
"resolutions": {
"vite": "8.0.0-beta.0"
}
}
```

```json [pnpm]
{
"pnpm": {
"overrides": {
"vite": "8.0.0-beta.0"
}
}
}
```

```json [Bun]
{
"overrides": {
"vite": "8.0.0-beta.0"
}
}
```

:::

添加这些覆盖后,重新安装你的依赖项,然后像往常一样启动开发服务器或构建你的项目。

## Vite 8 的附加功能 {#additional-features-in-vite-8}

除了搭载 Rolldown 之外,Vite 8 还带来了以下功能:

- **内置 tsconfig `paths` 支持**:开发者可以通过将 [`resolve.tsconfigPaths`](/config/shared-options.md#resolve-tsconfigpaths) 设置为 `true` 来启用此功能。此功能会带来轻微的性能成本,默认情况下未启用。
- **`emitDecoratorMetadata` 支持**:Vite 8 现在内置了对 TypeScript [`emitDecoratorMetadata` 选项](https://www.typescriptlang.org/tsconfig/#emitDecoratorMetadata)的自动支持。更多详情请参见[功能](/guide/features.md#emitdecoratormetadata)页面。

## 展望未来 {#looking-ahead}

速度一直是 Vite 的标志性特性。与 Rolldown 的集成,以及延伸至 Oxc,意味着 JavaScript 开发者可以从 Rust 的速度中获益。升级到 Vite 8 应该会仅仅因为使用 Rust 而带来性能提升。

我们也即将推出 Vite 的完整打包模式,这将大幅提高大型项目的开发服务器速度。初步结果显示,开发服务器启动速度快了 3 倍,完全重新加载快了 40%,网络请求减少了 10 倍。

另一个标志性的 Vite 特性是插件生态系统。我们希望 JavaScript 开发者能够继续使用他们熟悉的 JavaScript 语言来扩展和定制 Vite,同时从 Rust 的性能提升中受益。我们的团队正在与 VoidZero 团队合作,以加速这些基于 Rust 系统中的 JavaScript 插件使用。

目前正在试验的即将到来的优化包括:

- [**原始 AST 传输**](https://github.com/oxc-project/oxc/issues/2409)。允许 JavaScript 插件以最小的开销访问 Rust 生成的 AST。
- [**原生 MagicString 转换**](https://rolldown.rs/in-depth/native-magic-string#native-magicstring)。简单的自定义转换,逻辑在 JavaScript 中但计算在 Rust 中进行。

## **联系我们** {#connect-with-us}

如果你已经尝试过 Vite 8 测试版,我们很希望听到你的反馈!请报告任何问题或分享你的使用体验:

- **Discord**:加入我们的[社区服务器](https://chat.vite.dev/)进行实时讨论
- **GitHub**:在 [GitHub 讨论区](https://github.com/vitejs/vite/discussions)分享反馈
- **问题报告**:在 [rolldown-vite 仓库](https://github.com/vitejs/rolldown-vite/issues)报告 bug 和回归问题
- **成果分享**:在 [rolldown-vite-perf-wins 仓库](https://github.com/vitejs/rolldown-vite-perf-wins)分享你改善的构建时间

我们感谢所有的报告和复现案例。它们帮助我们朝着发布稳定版 8.0.0 的目标前进。
50 changes: 33 additions & 17 deletions config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
- **默认:** `'baseline-widely-available'`
- **相关内容:** [浏览器兼容性](/guide/build#browser-compatibility)

最终软件包的浏览器兼容性目标。默认值是 Vite 的一个特殊值 `'baseline-widely-available'`,该值针对的是包含在 20255 月 1 日广泛可用的 [Baseline](https://web-platform-dx.github.io/web-features/) 中的浏览器。具体来说,它是 `['chrome107', 'edge107', 'firefox104', 'safari16']`。
最终软件包的浏览器兼容性目标。默认值是 Vite 的一个特殊值 `'baseline-widely-available'`,该值针对的是包含在 20261 月 1 日广泛可用的 [Baseline](https://web-platform-dx.github.io/web-features/) 中的浏览器。具体来说,它是 `['chrome111', 'edge111', 'firefox114', 'safari16.4']`。

另一个特殊值是 `'esnext'` —— 即假设有原生动态导入支持,并只执行最低限度的转译。

转换过程将会由 esbuild 执行,并且此值应该是一个合法的 [esbuild 目标选项](https://esbuild.github.io/api/#target)。自定义目标也可以是一个 ES 版本(例如:`es2015`)、一个浏览器版本(例如:`chrome58`)或是多个目标组成的一个数组。
转换过程将会由 Oxc Transformer 执行,并且此值应该是一个合法的 [Oxc Transformer 目标选项](https://oxc.rs/docs/guide/usage/transformer/lowering#target)。自定义目标也可以是一个 ES 版本(例如:`es2015`)、一个浏览器版本(例如:`chrome58`)或是多个目标组成的一个数组。

注意:如果代码包含不能被 `esbuild` 安全地编译的特性,那么构建将会失败。查看 [esbuild 文档](https://esbuild.github.io/content-types/#javascript) 获取更多细节。
注意:如果代码包含不能被 `Oxc` 安全地编译的特性,那么构建将会输出警告。查看 [Oxc 文档](https://oxc.rs/docs/guide/usage/transformer/lowering#warnings) 获取更多细节。

## build.modulePreload {#build-modulepreload}

Expand Down Expand Up @@ -129,10 +129,16 @@ Git LFS 占位符会自动排除在内联之外,因为它们不包含其所表

## build.cssMinify {#build-cssminify}

- **类型:** `boolean | 'esbuild' | 'lightningcss'`
- **默认:** 对于客户端,与 [`build.minify`](#build-minify) 相同;对于 SSR,为 `'esbuild'`
- **类型:** `boolean | 'lightningcss' | 'esbuild'`
- **默认:** 对于客户端,与 [`build.minify`](#build-minify) 相同;对于 SSR,为 `'lightningcss'`

此选项允许用户覆盖 CSS 最小化压缩的配置,而不是使用默认的 `build.minify`,这样你就可以单独配置 JS 和 CSS 的最小化压缩方式。Vite 默认使用 `esbuild` 来最小化 CSS。将此选项设置为 `'lightningcss'` 可以改用 [Lightning CSS](https://lightningcss.dev/minification.html) 进行压缩。设置为该项,便可以使用 [`css.lightningcss`](./shared-options.md#css-lightningcss) 选项来进行配置。
此选项允许用户覆盖 CSS 最小化压缩的配置,而不是使用默认的 `build.minify`,这样你就可以单独配置 JS 和 CSS 的最小压缩方式。Vite 默认使用 [Lightning CSS](https://lightningcss.dev/minification.html) 来压缩 CSS。可以通过 [`css.lightningcss`](./shared-options.md#css-lightningcss) 进行配置。将此选项设置为 `'esbuild'` 可以改用 esbuild 进行压缩。

当设置为 `'esbuild'` 时,必须安装 esbuild。

```sh
npm add -D esbuild
```

## build.sourcemap {#build-sourcemap}

Expand All @@ -141,17 +147,20 @@ Git LFS 占位符会自动排除在内联之外,因为它们不包含其所表

构建后是否生成 source map 文件。如果为 `true`,将会创建一个独立的 source map 文件。如果为 `'inline'`,source map 将作为一个 data URI 附加在输出文件中。`'hidden'` 的工作原理与 `true` 相似,只是 bundle 文件中相应的注释将不被保留。

## build.rollupOptions {#build-rollupoptions}
## build.rolldownOptions {#build-rolldownoptions}

- **类型:** [`RollupOptions`](https://cn.rollupjs.org/configuration-options/)
- **类型:** [`RolldownOptions`](https://rollupjs.org/configuration-options/)

自定义底层的 Rollup 打包配置。这与从 Rollup 配置文件导出的选项相同,并将与 Vite 的内部 Rollup 选项合并。查看 [Rollup 选项文档](https://cn.rollupjs.org/configuration-options/) 获取更多细节。
<!-- TODO: update the link above and below to Rolldown's documentation -->

## build.commonjsOptions {#build-commonjsoptions}
自定义底层的 Rolldown 打包配置。这与从 Rolldown 配置文件导出的选项相同,并将与 Vite 的内部 Rolldown 选项合并。查看 [Rolldown 选项文档](https://cn.rollupjs.org/configuration-options/) 获取更多细节。

- **类型:** [`RollupCommonJSOptions`](https://github.com/rollup/plugins/tree/master/packages/commonjs#options)
## build.rollupOptions {#build-rollupoptions}

- **类型:** `RolldownOptions`
- **已弃用**

传递给 [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/master/packages/commonjs) 插件的选项
此选项是 `build.rolldownOptions` 选项的别名。请使用 `build.rolldownOptions` 选项代替

## build.dynamicImportVarsOptions {#build-dynamicimportvarsoptions}

Expand All @@ -160,6 +169,8 @@ Git LFS 占位符会自动排除在内联之外,因为它们不包含其所表

传递给 [@rollup/plugin-dynamic-import-vars](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars) 的选项。

<!-- TODO: we need to have a more detailed explanation here as we no longer use @rollup/plugin-dynamic-import-vars. we should say it's compatible with it though -->

## build.lib {#build-lib}

- **类型:** `{ entry: string | string[] | { [entryAlias: string]: string }, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[], fileName?: string | ((format: ModuleFormat, entryName: string) => string), cssFileName?: string }`
Expand Down Expand Up @@ -256,16 +267,19 @@ export default defineConfig({

## build.minify {#build-minify}

- **类型:** `boolean | 'terser' | 'esbuild'`
- **默认:** 客户端构建默认为`'esbuild'`,SSR构建默认为 `false`
- **类型:** `boolean | 'oxc' | 'terser' | 'esbuild'`
- **默认:** 客户端构建默认为`'oxc'`,SSR构建默认为 `false`

设置为 `false` 可以禁用最小化混淆,或是用来指定使用哪种混淆器。默认为 [Esbuild](https://github.com/evanw/esbuild),它比 terser 快 20-40 倍,压缩率只差 1%-2%。[Benchmarks](https://github.com/privatenumber/minification-benchmarks)
设置为 `false` 可以禁用最小化混淆,或是用来指定使用哪种混淆器。默认使用 [Oxc Minifier](https://oxc.rs/docs/guide/usage/minifier),它比 terser 快 30~90 倍,但压缩率仅差 0.5~2%。[基准测试](https://github.com/privatenumber/minification-benchmarks)
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There's a mix of terminology used for "minification" in Chinese. The text uses both "最小化压缩" and "最小化混淆" on this line. The term "最小化混淆" (minification and obfuscation) is technically more accurate than just "最小化" (minimization), but it should be consistent with other parts of the document. Line 135 uses "最小化压缩", so consider using consistent terminology throughout.

Suggested change
设置为 `false` 可以禁用最小化混淆,或是用来指定使用哪种混淆器。默认使用 [Oxc Minifier](https://oxc.rs/docs/guide/usage/minifier),它比 terser 快 30~90 倍,但压缩率仅差 0.5~2%。[基准测试](https://github.com/privatenumber/minification-benchmarks)
设置为 `false` 可以禁用最小化压缩,或是用来指定使用哪种混淆器。默认使用 [Oxc Minifier](https://oxc.rs/docs/guide/usage/minifier),它比 terser 快 30~90 倍,但压缩率仅差 0.5~2%。[基准测试](https://github.com/privatenumber/minification-benchmarks)

Copilot uses AI. Check for mistakes.

`build.minify: 'esbuild'` 已弃用,将在未来版本中移除。

注意,在 lib 模式下使用 `'es'` 时,`build.minify` 选项不会缩减空格,因为会移除掉 pure 标注,导致破坏 tree-shaking。

当设置为 `'terser'` 时必须先安装 Terser。
当设置为 `'esbuild'` 或 `'terser'` 时,必须分别安装 esbuild 或 Terser。

```sh
npm add -D esbuild
npm add -D terser
```

Expand Down Expand Up @@ -314,7 +328,9 @@ npm add -D terser

## build.watch {#build-watch}

- **类型:** [`WatcherOptions`](https://cn.rollupjs.org/configuration-options/#watch)`| null`
<!-- TODO: update the link below to Rolldown's documentation -->

- **类型:** [`WatcherOptions`](https://rollupjs.org/configuration-options/#watch)`| null`
- **默认:** `null`

设置为 `{}` 则会启用 rollup 的监听器。对于只在构建阶段或者集成流程使用的插件很常用。
Expand Down
25 changes: 19 additions & 6 deletions config/dep-optimization-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ export default defineConfig({
})
```

## optimizeDeps.rolldownOptions <NonInheritBadge /> {#optimizedeps-rolldownoptions}

- **类型:** [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)`<``RolldownOptions`, `'input' | 'logLevel' | 'output'> & {
output?: [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)`<`
`RolldownOutputOptions`,
`'format' | 'sourcemap' | 'dir' | 'banner'>`
`}`

<!-- TODO: add link to RolldownOptions -->
<!-- TODO: add link to RolldownOutputOptions -->

在依赖扫描和优化过程中传递给 Rolldown 的选项。

某些选项进行了省略,因为修改它们与 Vite 的优化方案并不兼容。

- `plugins` 与 Vite 的 dep 插件合并

## optimizeDeps.esbuildOptions <NonInheritBadge /> {#optimizedeps-esbuildoptions}

- **类型:** [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)`<`[`EsbuildBuildOptions`](https://esbuild.github.io/api/#general-options)`,
Expand All @@ -64,13 +81,9 @@ export default defineConfig({
| 'outbase'
| 'outExtension'
| 'metafile'>`
- **已弃用**

在依赖扫描和优化过程中传递给 esbuild 的选项。

某些选项进行了省略,因为修改它们与 Vite 的优化方案并不兼容。

- 忽略了 `external` 选项,请使用 Vite 的 `optimizeDeps.exclude` 选项
- `plugins` 与 Vite 的 dep 插件合并
此选项在内部被转换为 `optimizeDeps.rolldownOptions`。请使用 `optimizeDeps.rolldownOptions` 代替。

## optimizeDeps.force <NonInheritBadge /> {#optimizedeps-force}

Expand Down
2 changes: 1 addition & 1 deletion config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ vite --config my-config.js
```

::: tip 加载配置文件
默认情况下,Vite 使用 `esbuild` 将配置文件打包到临时文件中并加载它。这可能会在 monorepo 中导入 TypeScript 文件时引发问题。如果你遇到了这种方法问题,可以通过指定 `--configLoader runner` 以改用 [module runner](/guide/api-environment-runtimes.html#modulerunner),它不会创建临时配置并将动态转换任何文件。请注意,module runner 不支持配置文件中的 CJS,但外部 CJS 包应该可以正常工作。
默认情况下,Vite 使用 [Rolldown](https://rolldown.rs/) 将配置文件打包到临时文件中并加载它。这可能会在 monorepo 中导入 TypeScript 文件时引发问题。如果你遇到了这种方法问题,可以通过指定 `--configLoader runner` 以改用 [module runner](/guide/api-environment-runtimes.html#modulerunner),它不会创建临时配置并将动态转换任何文件。请注意,module runner 不支持配置文件中的 CJS,但外部 CJS 包应该可以正常工作。

另外,如果你正在使用支持TypeScript的环境(例如 `node --experimental-strip-types`),或者只编写纯 JavaScript 代码,你可以指定 `--configLoader native` 以使用环境的本机运行时加载配置文件。请注意,配置文件导入的模块的更新不会被检测到,因此不会自动重启 Vite 服务器。
:::
Expand Down
Loading