Skip to content

Commit 915d11d

Browse files
authored
release: v2.5.0
release: v2.5.0
2 parents 34d923c + defec80 commit 915d11d

File tree

10 files changed

+63
-18
lines changed

10 files changed

+63
-18
lines changed

.vitepress/theme/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,14 @@ export default {
3333
)
3434
])
3535
})
36+
},
37+
enhanceApp({ app, router, siteData }) {
38+
// app is the Vue 3 app instance from `createApp()`. router is VitePress'
39+
// custom router. `siteData`` is a `ref`` of current site-level metadata.
40+
app.directive('href', {
41+
mounted(el, binding) {
42+
el.href = binding.value;
43+
}
44+
})
3645
}
3746
}

blog/announcing-vite2.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Vite 将 CSS 看作模块系统中的一等公民,并且内置了以下支持
4646

4747
### 服务端渲染(SSR)支持 {#server-side-rendering-ssr-support}
4848

49-
Vite 2.0 提供 [实验性的 SSR 支持](/guide/ssr)。Vite 提供一个灵活的 API 来在 Node.js 中高效率地直接加载 ESM 源码(并且同样有精准的更新而不需要打包)。提供 CommonJS 版本的依赖会在 SSR 时自动被跳过转换直接加载。生产环境下,服务器可以和 Vite 完全解耦。基于 Vite SSR 的架构也可以很方便的做静态预渲染(SSG)。
49+
Vite 2.0 提供 [实验性的 SSR 支持](/guide/ssr)。Vite 提供了灵活的 API,以便于在开发过程中直接通过 Node.js 高效率地加载和更新 ESM 的源码(几乎与服务端的 HMR 一致),并自动外部化与 CommonJS 兼容的依赖关系,以提高开发和 SSR 的构建速度。生产环境下,服务器可以和 Vite 完全解耦。基于 Vite SSR 的架构也可以很方便的做静态预渲染(SSG)。
5050

5151
Vite SSR 会作为一个底层功能,而我们期待看到更高层级的框架在此基础上的应用。
5252

config/index.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default defineConfig(async ({ command, mode }) => {
7878
return {
7979
// 构建模式所需的特有配置
8080
}
81-
}
81+
})
8282
```
8383

8484
## 共享配置 {#shared-options}
@@ -213,7 +213,7 @@ export default defineConfig(async ({ command, mode }) => {
213213
```ts
214214
interface CSSModulesOptions {
215215
scopeBehaviour?: 'global' | 'local'
216-
globalModulePaths?: string[]
216+
globalModulePaths?: RegExp[]
217217
generateScopedName?:
218218
| string
219219
| ((name: string, filename: string, css: string) => string)
@@ -396,7 +396,7 @@ export default defineConfig(async ({ command, mode }) => {
396396
server: {
397397
proxy: {
398398
// 字符串简写写法
399-
'/foo': 'http://localhost:4567/foo',
399+
'/foo': 'http://localhost:4567',
400400
// 选项写法
401401
'/api': {
402402
target: 'http://jsonplaceholder.typicode.com',
@@ -453,6 +453,8 @@ export default defineConfig(async ({ command, mode }) => {
453453

454454
传递给 [chokidar](https://github.com/paulmillr/chokidar#api) 的文件系统监听器选项。
455455

456+
当需要再 Windows Subsystem for Linux (WSL) 2 上运行 Vite 时,如果项目文件夹位于 Windows 文件系统中,你需要将此选项设置为 `{ usePolling: true }`。这是由于 Windows 文件系统的 [WSL2 限制](https://github.com/microsoft/WSL/issues/4739) 造成的。
457+
456458
### server.middlewareMode {#server-middlewaremode}
457459

458460
- **类型:** `'ssr' | 'html'`
@@ -543,6 +545,21 @@ createServer()
543545

544546
注意:如果代码包含不能被 `esbuild` 安全地编译的特性,那么构建将会失败。查看 [esbuild 文档](https://esbuild.github.io/content-types/#javascript) 获取更多细节。
545547

548+
### build.polyfillModulePreload {#build-polyfillmodulepreload}
549+
550+
- **类型:** `boolean`
551+
- **默认值:** `true`
552+
553+
用于决定是否自动注入 [module preload 的 polyfill](https://guybedford.com/es-module-preloading-integrity#modulepreload-polyfill).
554+
555+
如果设置为 `true`,此 polyfill 会被自动注入到每个 `index.html` 入口的 proxy 模块中。如果是通过 `build.rollupOptions.input` 将构建配置为使用非 html 的自定义入口,那么则需要在你自定义入口中手动引入 polyfill:
556+
557+
```js
558+
import 'vite/modulepreload-polyfill'
559+
```
560+
561+
注意:此 polyfill **不适用于** [Library 模式](/guide/build#library-mode)。如果你需要支持不支持动态引入的浏览器,你应该避免在你的库中使用此选项。
562+
546563
### build.outDir {#build-outdir}
547564

548565
- **类型:** `string`

guide/assets.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import InlineWorker from './shader.js?worker&inline'
8585

8686
## new URL(url, import.meta.url)
8787

88-
[import.meta.url](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import.meta) 是一个 ESM 的原生功能,会暴露当前模块的 URL。将它与原生的 [URL 构造器](https://developer.mozilla.org/en-US/docs/Web/API/URL) 组合使用,在一个 JavaScript 模块中,通过相对路径我们就能得到一个被完整解析的静态资源 URL:
88+
<a v-href="'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import'+'.meta'">import.meta.url</a> 是一个 ESM 的原生功能,会暴露当前模块的 URL。将它与原生的 [URL 构造器](https://developer.mozilla.org/en-US/docs/Web/API/URL) 组合使用,在一个 JavaScript 模块中,通过相对路径我们就能得到一个被完整解析的静态资源 URL:
8989

9090
```js
9191
const imgUrl = new URL('./img.png', import.meta.url)

guide/backend-integration.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# 后端集成 {#backend-integration}
22

3+
:::tip Note
34
如果你想使用传统的后端(如 Rails, Laravel)来服务 HTML,但使用 Vite 来服务其他资源,可以查看在 [Awesome Vite](https://github.com/vitejs/awesome-vite#integrations-with-backends) 上的已有的后端集成列表。
45

5-
或者你可以按照如下步骤手动配置:
6+
如果你需要自定义集成,你可以按照本指南的步骤配置它:
7+
:::
68

79
1. 在你的 Vite 配置中配置入口文件和启用创建 `manifest`
810

@@ -20,6 +22,13 @@
2022
})
2123
```
2224

25+
如果你没有禁用 [module preload 的 polyfill](/config/#build-polyfillmodulepreload),你还需在你的入口处添加此 polyfill:
26+
27+
```js
28+
// 在你应用的入口起始处添加此 polyfill
29+
import 'vite/modulepreload-polyfill'
30+
```
31+
2332
2. 在开发环境中,在服务器的 HTML 模板中注入以下内容(用正在运行的本地 URL 替换 `http://localhost:3000`):
2433

2534
```html

guide/migration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
- `httpsOptions` 已被删除,[`server.https`](/config/#server-https) 可以直接接收选项对象。
3232
- `chokidarWatchOptions` 变更为 [`server.watch`](/config/#server-watch)
3333

34-
- [`assetsInclude`](/config/#assetsInclude) 现在接收 `string | RegExp | (string | RegExp)[]` 而不是一个函数。
34+
- [`assetsInclude`](/config/#assetsinclude) 现在接收 `string | RegExp | (string | RegExp)[]` 而不是一个函数。
3535

3636
- 所有 Vue 特定选项都已移除;应将选项传递给 Vue 插件。
3737

3838
## 别名用法变化 {#alias-behavior-change}
3939

40-
[`alias`](/config/#alias) 现在会被传递给 `@rollup/plugin-alias` 并不再需要开始/结尾处的斜线了。此行为目前是一个直接替换,所以 1.0 风格的目录别名需要删除其结尾处的斜线:
40+
[`alias`](/config/#resolve-alias) 现在会被传递给 `@rollup/plugin-alias` 并不再需要开始/结尾处的斜线了。此行为目前是一个直接替换,所以 1.0 风格的目录别名需要删除其结尾处的斜线:
4141

4242
```diff
4343
- alias: { '/@foo/': path.resolve(__dirname, 'some-special-dir') }

guide/static-deploy.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -138,24 +138,28 @@ $ npm run preview
138138

139139
如果你要部署在 `https://<USERNAME or GROUP>.gitlab.io/<REPO>/` 上,例如你的仓库地址为 `https://gitlab.com/<USERNAME>/<REPO>`,那么请设置 `base` 为 `'/<REPO>/'`。
140140

141-
2. 在 `vite.config.js` 中设置 `build.outDir` 为 `public`。
142-
143-
3. 在项目根目录创建一个 `.gitlab-ci.yml` 文件,并包含以下内容。它将使得每次你更改内容时都重新构建与部署站点:
141+
2. 在项目根目录创建一个 `.gitlab-ci.yml` 文件,并包含以下内容。它将使得每次你更改内容时都重新构建与部署站点:
144142

145143
```yaml
146-
image: node:10.22.0
144+
image: node:16.5.0
147145
pages:
146+
stage: deploy
148147
cache:
148+
key:
149+
files:
150+
- package-lock.json
151+
prefix: npm
149152
paths:
150153
- node_modules/
151154
script:
152155
- npm install
153156
- npm run build
157+
- cp -a dist/. public/
154158
artifacts:
155159
paths:
156160
- public
157-
only:
158-
- master
161+
rules:
162+
- $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
159163
```
160164

161165
## Netlify {#netlify}
@@ -188,9 +192,9 @@ $ npm run preview
188192

189193
```js
190194
{
191-
"projects": {
192-
"default": "<YOUR_FIREBASE_ID>"
193-
}
195+
"projects": {
196+
"default": "<YOUR_FIREBASE_ID>"
197+
}
194198
}
195199
```
196200

guide/using-plugins.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Vite 旨在为常见的 Web 开发范式提供开箱即用的支持。在寻找
3636

3737
查看 [Plugins 章节](../plugins/) 获取官方插件信息。社区插件列表请参见 [awesome-vite](https://github.com/vitejs/awesome-vite#plugins)。而对于兼容的 Rollup 插件,请查看 [Vite Rollup 插件](https://vite-rollup-plugins.patak.dev) 获取一个带使用说明的兼容 Rollup 官方插件列表,若列表中没有找到,则请参阅 [Rollup 插件兼容性章节](../guide/api-plugin#rollup-plugin-compatibility)
3838

39-
你也可以使用此 [npm Vite 插件搜索链接](https://www.npmjs.com/search?q=vite-plugin&ranking=popularity) 来找到一些遵循了 [推荐约定](./api-plugin.md#conventions) 的 Vite 插件,或者此 [npm Rollup 插件搜索链接](https://www.npmjs.com/search?q=rollup-plugin&ranking=popularity) 获取 Rollup 插件。
39+
你也可以使用此 [npm Vite 插件搜索链接](https://www.npmjs.com/search?q=vite-plugin&ranking=popularity) 来找到一些遵循了 [推荐约定](./api-plugin.md#conventions) 的 Vite 插件,或者通过 [npm Rollup 插件搜索链接](https://www.npmjs.com/search?q=rollup-plugin&ranking=popularity) 获取 Rollup 插件。
4040

4141
## 强制插件排序 {#enforcing-plugin-ordering}
4242

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"private": true,
99
"devDependencies": {
1010
"chalk": "^4.1.0",
11+
"patch-vue-directive-ssr": "^0.0.1",
1112
"vitepress": "^0.12.2",
1213
"yorkie": "^2.0.0"
1314
},

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,11 @@ p-finally@^1.0.0:
10571057
resolved "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
10581058
integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=
10591059

1060+
patch-vue-directive-ssr@^0.0.1:
1061+
version "0.0.1"
1062+
resolved "https://registry.npmjs.org/patch-vue-directive-ssr/-/patch-vue-directive-ssr-0.0.1.tgz#2eac731f59cdb766d4d613bc24e522ded6ff1bb8"
1063+
integrity sha512-n84llktHah+EXUGo+RvmTJcAQJQVW0kHHHiJ34ZSLijzhHi32zCMjCc5VAFv4jmdC91bpaYGPk0cDW1D8hQ3GQ==
1064+
10601065
path-key@^2.0.0:
10611066
version "2.0.1"
10621067
resolved "https://registry.npmjs.org/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40"

0 commit comments

Comments
 (0)