diff --git a/.vitepress/theme/components/landing/4. community-section/CommunitySection.vue b/.vitepress/theme/components/landing/4. community-section/CommunitySection.vue index c4a9fccb..6158502f 100644 --- a/.vitepress/theme/components/landing/4. community-section/CommunitySection.vue +++ b/.vitepress/theme/components/landing/4. community-section/CommunitySection.vue @@ -70,7 +70,7 @@ SolidJS in mind, they should scale from our simplest template to opinionated sta name: 'Christoph Nakazawa', handle: '@cpojer', avatar: - 'https://pbs.twimg.com/profile_images/1189537722286952449/OrscO0bD_400x400.jpg', + 'https://pbs.twimg.com/profile_images/1854151427595407360/4GyUCgEH_400x400.jpg', comment: ['Vite is gonna eat the (JavaScript) world.'], }, { diff --git a/guide/api-environment-runtimes.md b/guide/api-environment-runtimes.md index aad5f3ac..5e0bb4e8 100644 --- a/guide/api-environment-runtimes.md +++ b/guide/api-environment-runtimes.md @@ -190,15 +190,10 @@ export interface ModuleRunnerOptions { | InterceptorOptions /** * 禁用 HMR 或配置 HMR 选项 + * + * @default true */ - hmr?: - | false - | { - /** - * 配置 HMR 日志. - */ - logger?: false | HMRLogger - } + hmr?: boolean | ModuleRunnerHmr /** * 自定义模块缓存。如果未提供,它将创建一个单独的模块缓存给 * 每个模块运行器实例 @@ -356,6 +351,7 @@ export const runner = new ModuleRunner( return response.json() }, }, + hmr: false, // disable HMR as HMR requires transport.connect }, new ESModulesEvaluator(), ) diff --git a/guide/migration.md b/guide/migration.md index a281fd5a..ee1744af 100644 --- a/guide/migration.md +++ b/guide/migration.md @@ -100,7 +100,54 @@ Vite 6 扩展了对更多 HTML 元素的支持。完整列表请参见 [HTML 功 - [[#18493] refactor!: remove fs.cachedChecks option](https://github.com/vitejs/vite/pull/18493) - 由于在缓存文件夹中写入文件并立即导入时会出现边缘情况,因此删除了这一选择优化。 - [[#18697] fix(deps)!: update dependency dotenv-expand to v12](https://github.com/vitejs/vite/pull/18697) - - 插值中使用的变量应在插值之前声明。更多详情,请参阅 [`dotenv-expand` changelog](https://github.com/motdotla/dotenv-expand/blob/v12.0.1/CHANGELOG.md#1200-2024-11-16). + - 插值中使用的变量应在插值之前声明。更多详情,请参阅 [`dotenv-expand` changelog](https://github.com/motdotla/dotenv-expand/blob/v12.0.1/CHANGELOG.md#1200-2024-11-16)。 +- [[#16471] feat: v6 - Environment API](https://github.com/vitejs/vite/pull/16471) + + - 对仅 SSR 模块的更新不再触发客户端的页面重载。要恢复以前的行为,可使用自定义 Vite 插件: +
+ 点击展开示例 + + ```ts twoslash + import type { Plugin, EnvironmentModuleNode } from 'vite' + + function hmrReload(): Plugin { + return { + name: 'hmr-reload', + enforce: 'post', + hotUpdate: { + order: 'post', + handler({ modules, server, timestamp }) { + if (this.environment.name !== 'ssr') return + + let hasSsrOnlyModules = false + + const invalidatedModules = new Set() + for (const mod of modules) { + if (mod.id == null) continue + const clientModule = + server.environments.client.moduleGraph.getModuleById(mod.id) + if (clientModule != null) continue + + this.environment.moduleGraph.invalidateModule( + mod, + invalidatedModules, + timestamp, + true, + ) + hasSsrOnlyModules = true + } + + if (hasSsrOnlyModules) { + server.ws.send({ type: 'full-reload' }) + return [] + } + }, + }, + } + } + ``` + +
## 从 v4 迁移 {#migration-from-v4}