Skip to content

Commit 1e5f28d

Browse files
release: v3.0.2 Merge pull request #556 from vitejs/dev
2 parents c20ede7 + 293426b commit 1e5f28d

23 files changed

+231
-33
lines changed

.vitepress/theme/components/AsideSponsors.vue

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,71 @@ const sponsors = computed(() => {
1818
</script>
1919

2020
<template>
21+
<a class="viteconf" href="https://viteconf.org" target="_blank">
22+
<img width="22" height="22" src="/viteconf.svg" />
23+
<span>
24+
<p class="extra-info">Free Online Conference</p>
25+
<p class="heading">ViteConf - Oct 11</p>
26+
<p class="extra-info">Get your ticket now!</p>
27+
</span>
28+
</a>
2129
<VPDocAsideSponsors v-if="data" :data="sponsors" />
2230
</template>
31+
32+
<style>
33+
.viteconf {
34+
margin-top: 1rem;
35+
margin-bottom: 1rem;
36+
border-radius: 14px;
37+
padding-left: 2.5rem;
38+
padding-top: 0.4rem;
39+
padding-bottom: 0.4rem;
40+
position: relative;
41+
font-size: 1rem;
42+
font-weight: 700;
43+
line-height: 1.1rem;
44+
filter: grayscale(100%);
45+
display: flex;
46+
align-items: center;
47+
justify-content: center;
48+
gap: 0.75rem;
49+
background-color: var(--vp-c-bg-alt);
50+
border: 2px solid var(--vp-c-bg-alt);
51+
transition: border-color 0.5s;
52+
}
53+
.viteconf:hover {
54+
filter: grayscale(0%);
55+
border: 2px solid var(--vp-c-brand-light);
56+
}
57+
.viteconf img {
58+
position: absolute;
59+
left: 1.5rem;
60+
transition: transform 0.5s;
61+
}
62+
.viteconf:hover img {
63+
transform: scale(1.75);
64+
}
65+
66+
.viteconf:hover .heading {
67+
background-image: linear-gradient(
68+
120deg,
69+
#bd34fe 16%,
70+
var(--vp-c-brand-light),
71+
var(--vp-c-brand-light)
72+
);
73+
background-clip: text;
74+
-webkit-background-clip: text;
75+
-webkit-text-fill-color: transparent;
76+
}
77+
78+
.viteconf .extra-info {
79+
color: var(--vp-c-text-1);
80+
opacity: 0;
81+
font-size: 0.7rem;
82+
padding-left: 0.1rem;
83+
transition: opacity 0.5s;
84+
}
85+
.viteconf:hover .extra-info {
86+
opacity: 0.9;
87+
}
88+
</style>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<script setup lang="ts">
2+
defineProps<{ svg: string }>()
3+
</script>
4+
5+
<template>
6+
<figure class="svg-image-root" v-html="svg" />
7+
</template>
8+
9+
<style>
10+
.svg-image-root {
11+
background-color: #eee;
12+
border-radius: 8px;
13+
padding: 1ch;
14+
margin: 1ch 0;
15+
}
16+
html.dark .svg-image-root {
17+
background-color: #313641;
18+
}
19+
.svg-image-root svg text {
20+
font-family: var(--vp-font-family-base);
21+
}
22+
</style>

.vitepress/theme/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Theme from 'vitepress/theme'
33
import './styles/vars.css'
44
import HomeSponsors from './components/HomeSponsors.vue'
55
import AsideSponsors from './components/AsideSponsors.vue'
6+
import SvgImage from './components/SvgImage.vue'
67

78
export default {
89
...Theme,
@@ -11,5 +12,8 @@ export default {
1112
'home-features-after': () => h(HomeSponsors),
1213
'aside-ads-before': () => h(AsideSponsors)
1314
})
15+
},
16+
enhanceApp({ app }) {
17+
app.component('SvgImage', SvgImage)
1418
}
1519
}

blog/announcing-vite3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ There are other deploy scenarios where this isn't enough. For example, if the ge
193193

194194
### Esbuild Deps Optimization at Build Time (Experimental)
195195

196-
One of the main differences between dev and build time is how Vite handles dependencies. During build time, [`@rollupjs/plugin-commonjs`](https://github.com/rollup/plugins/tree/master/packages/commonjs) is used to allow importing CJS only dependencies (like React). When using the dev server, esbuild is used instead to pre-bundle and optimize dependencies, and an inline interop scheme is applied while transforming user code importing CJS deps. During the development of Vite 3, we introduced the changes needed to also allow the use of [esbuild to optimize dependencies during build time](/guide/migration.html#using-esbuild-deps-optimization-at-build-time). [`@rollupjs/plugin-commonjs`](https://github.com/rollup/plugins/tree/master/packages/commonjs) can then be avoided, making dev and build time work in the same way.
196+
One of the main differences between dev and build time is how Vite handles dependencies. During build time, [`@rollup/plugin-commonjs`](https://github.com/rollup/plugins/tree/master/packages/commonjs) is used to allow importing CJS only dependencies (like React). When using the dev server, esbuild is used instead to pre-bundle and optimize dependencies, and an inline interop scheme is applied while transforming user code importing CJS deps. During the development of Vite 3, we introduced the changes needed to also allow the use of [esbuild to optimize dependencies during build time](/guide/migration.html#using-esbuild-deps-optimization-at-build-time). [`@rollup/plugin-commonjs`](https://github.com/rollup/plugins/tree/master/packages/commonjs) can then be avoided, making dev and build time work in the same way.
197197

198198
Given that Rollup v3 will be out in the next months, and we're going to follow up with another Vite major, we've decided to make this mode optional to reduce v3 scope and give Vite and the ecosystem more time to work out possible issues with the new CJS interop approach during build time. Frameworks may switch to using esbuild deps optimization during build time by default at their own pace before Vite 4.
199199

@@ -223,7 +223,7 @@ A triaging marathon was spearheaded by [@bluwyoo](https://twitter.com/bluwyoo),
223223

224224
## Compatibility Notes
225225

226-
- Vite no longer supports Node.js 12, which reached its EOL. Node.js 14.18+ is now required.
226+
- Vite no longer supports Node.js 12 / 13 / 15, which reached its EOL. Node.js 14.18+ / 16+ is now required.
227227
- Vite is now published as ESM, with a CJS proxy to the ESM entry for compatibility.
228228
- The Modern Browser Baseline now targets browsers which support the [native ES Modules](https://caniuse.com/es6-module), [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import), and [`import.meta`](https://caniuse.com/mdn-javascript_statements_import_meta) features.
229229
- JS file extensions in SSR and library mode now use a valid extension (`js`, `mjs`, or `cjs`) for output JS entries and chunks based on their format and the package type.

config/build-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- **默认:** `'modules'`
77
- **相关内容:** [浏览器兼容性](/guide/build#browser-compatibility)
88

9-
设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——`'modules'`,这是指 [支持原生 ES 模块的浏览器](https://caniuse.com/es6-module)
9+
设置最终构建的浏览器兼容目标。默认值是一个 Vite 特有的值——`'modules'`,这是指 [支持原生 ES 模块](https://caniuse.com/es6-module)[原生 ESM 动态导入](https://caniuse.com/es6-module-dynamic-import)[`import.meta`](https://caniuse.com/mdn-javascript_statements_import_meta) 的浏览器
1010

1111
另一个特殊值是 “esnext” —— 即假设有原生动态导入支持,并且将会转译得尽可能小:
1212

config/index.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@ export default {
2121
vite --config my-config.js
2222
```
2323

24-
::: tip 注意
25-
注意,Vite 会在 **CommonJS****TypeScript** 配置文件中替换 `__filename``__dirname` 以及 `import.meta.url`。如果使用这些名称作为变量名可能会导致代码报错:
26-
27-
```js
28-
const __filename = 'value' // SyntaxError: Identifier '__filename' has already been declared
29-
30-
const func = () => {
31-
const __filename = 'value' // no error
32-
}
33-
```
34-
35-
:::
36-
3724
## 配置智能提示 {#config-intellisense}
3825

3926
因为 Vite 本身附带 Typescript 类型,所以你可以通过 IDE 和 jsdoc 的配合来实现智能提示:

guide/backend-integration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
```html
3535
<!-- 如果是在开发环境中 -->
36-
<script type="module" src="http://localhost:3000/@vite/client"></script>
36+
<script type="module" src="http://localhost:5173/@vite/client"></script>
37+
<script type="module" src="http://localhost:5173/main.js"></script>
3738
```
3839

3940
为了正确地提供资源,你有两种选项:

guide/build.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## 浏览器兼容性 {#browser-compatibility}
66

7-
用于生产环境的构建包会假设目标浏览器支持现代 JavaScript 语法。默认情况下,Vite 的目标浏览器是指能够 [支持原生 ESM script 标签](https://caniuse.com/es6-module)[支持原生 ESM 动态导入](https://caniuse.com/es6-module-dynamic-import) 的。作为参考,Vite 使用这个 [browserslist](https://github.com/browserslist/browserslist) 作为查询标准
7+
用于生产环境的构建包会假设目标浏览器支持现代 JavaScript 语法。默认情况下,Vite 的目标是能够 [支持原生 ESM script 标签](https://caniuse.com/es6-module)[支持原生 ESM 动态导入](https://caniuse.com/es6-module-dynamic-import) [`import.meta`](https://caniuse.com/mdn-javascript_statements_import_meta) 的浏览器
88

99
- Chrome >=87
1010
- Firefox >=78
@@ -187,6 +187,10 @@ dist/my-lib.umd.cjs 0.30 KiB / gzip: 0.16 KiB
187187
如果 `package.json` 不包含 `"type": "module"`,Vite 会生成不同的文件后缀名以兼容 Node.js。`.js` 会变为 `.mjs``.cjs` 会变为 `.js`.
188188
:::
189189

190+
::: tip 环境变量
191+
在库模式下,所有 `import.meta.env.*` 用法在构建生产时都会被静态替换。但是,`process.env.*` 的用法不会被替换,所以你的库的使用者可以动态地更改它。如果不想允许他们这样做,你可以使用 `define: { 'process.env.`<wbr>`NODE_ENV': '"production"' }` 例如静态替换它们。
192+
:::
193+
190194
## 进阶基础路径选项 {#advanced-base-options}
191195

192196
::: warning

guide/env-and-mode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ DB_PASSWORD=foobar
5959
console.log(import.meta.env.VITE_SOME_KEY) // 123
6060
console.log(import.meta.env.DB_PASSWORD) // undefined
6161
```
62-
如果你想自定义 env 变量的前缀,请参阅 [envPrefix](/config/index#envprefix)。
62+
如果你想自定义 env 变量的前缀,请参阅 [envPrefix](/config/shared-options.html#envprefix)。
6363
6464
:::warning 安全注意事项
6565

guide/features.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ Vite 会为入口 chunk 和它们在打包出的 HTML 中的直接引入自动
538538

539539
在实际项目中,Rollup 通常会生成 “共用” chunk —— 被两个或以上的其他 chunk 共享的 chunk。与动态导入相结合,会很容易出现下面这种场景:
540540

541-
![graph](/images/graph.png)
541+
<script setup>
542+
import graphSvg from '../images/graph.svg?raw'
543+
</script>
544+
<svg-image :svg="graphSvg" />
542545

543546
在无优化的情境下,当异步 chunk `A` 被导入时,浏览器将必须请求和解析 `A`,然后它才能弄清楚它也需要共用 chunk `C`。这会导致额外的网络往返:
544547

0 commit comments

Comments
 (0)