Skip to content

Commit 07aef1b

Browse files
authoredJul 8, 2022
docs: cleanup changes (#8989)
1 parent 33d6177 commit 07aef1b

File tree

13 files changed

+97
-121
lines changed

13 files changed

+97
-121
lines changed
 

Diff for: ‎docs/config/server-options.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ Create Vite server in middleware mode.
198198
- **Example:**
199199

200200
```js
201-
const express = require('express')
202-
const { createServer: createViteServer } = require('vite')
201+
import express from 'express'
202+
import { createServer as createViteServer } from 'vite'
203203

204204
async function createServer() {
205205
const app = express()

Diff for: ‎docs/guide/api-javascript.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ async function createServer(inlineConfig?: InlineConfig): Promise<ViteDevServer>
1313
**Example Usage:**
1414

1515
```js
16-
const { createServer } = require('vite')
16+
import { fileURLToPath } from 'url'
17+
import { createServer } from 'vite'
18+
19+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
1720
1821
;(async () => {
1922
const server = await createServer({
@@ -134,8 +137,11 @@ async function build(
134137
**Example Usage:**
135138

136139
```js
137-
const path = require('path')
138-
const { build } = require('vite')
140+
import path from 'path'
141+
import { fileURLToPath } from 'url'
142+
import { build } from 'vite'
143+
144+
const __dirname = fileURLToPath(new URL('.', import.meta.url))
139145
140146
;(async () => {
141147
await build({
@@ -161,8 +167,7 @@ async function preview(inlineConfig?: InlineConfig): Promise<PreviewServer>
161167
**Example Usage:**
162168

163169
```js
164-
const { preview } = require('vite')
165-
170+
import { preview } from 'vite'
166171
;(async () => {
167172
const previewServer = await preview({
168173
// any valid user config options, plus `mode` and `configFile`

Diff for: ‎docs/guide/api-plugin.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Vite strives to offer established patterns out of the box, so before creating a
1111
When creating a plugin, you can inline it in your `vite.config.js`. There is no need to create a new package for it. Once you see that a plugin was useful in your projects, consider sharing it to help others [in the ecosystem](https://chat.vitejs.dev).
1212

1313
::: tip
14-
When learning, debugging, or authoring plugins we suggest including [vite-plugin-inspect](https://github.com/antfu/vite-plugin-inspect) in your project. It allows you to inspect the intermediate state of Vite plugins. After installing, you can visit `localhost:5173/__inspect/` to inspect the modules and transformation stack of your project. Check out install instructions in the [vite-plugin-inspect docs](https://github.com/antfu/vite-plugin-inspect).
14+
When learning, debugging, or authoring plugins, we suggest including [vite-plugin-inspect](https://github.com/antfu/vite-plugin-inspect) in your project. It allows you to inspect the intermediate state of Vite plugins. After installing, you can visit `localhost:5173/__inspect/` to inspect the modules and transformation stack of your project. Check out install instructions in the [vite-plugin-inspect docs](https://github.com/antfu/vite-plugin-inspect).
1515
![vite-plugin-inspect](/images/vite-plugin-inspect.png)
1616
:::
1717

@@ -199,7 +199,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
199199
name: 'mutate-config',
200200
config(config, { command }) {
201201
if (command === 'build') {
202-
config.root = __dirname
202+
config.root = 'foo'
203203
}
204204
}
205205
})

Diff for: ‎docs/guide/assets.md

-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,3 @@ const imgUrl = new URL(imagePath, import.meta.url).href
113113
::: warning Does not work with SSR
114114
This pattern does not work if you are using Vite for Server-Side Rendering, because `import.meta.url` have different semantics in browsers vs. Node.js. The server bundle also cannot determine the client host URL ahead of time.
115115
:::
116-
117-
::: warning `target` needs to be `es2020` or higher
118-
This pattern will not work if [build-target](/config/build-options.md#build-target) or [optimizedeps.esbuildoptions.target](/config/dep-optimization-options.md#optimizedeps-esbuildoptions) is set to a value lower than `es2020`.
119-
:::

Diff for: ‎docs/guide/build.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The build can be customized via various [build config options](/config/build-opt
3535

3636
```js
3737
// vite.config.js
38-
module.exports = defineConfig({
38+
export default defineConfig({
3939
build: {
4040
rollupOptions: {
4141
// https://rollupjs.org/guide/en/#big-list-of-options
@@ -53,7 +53,7 @@ You can configure how chunks are split using `build.rollupOptions.output.manualC
5353
```js
5454
// vite.config.js
5555
import { splitVendorChunkPlugin } from 'vite'
56-
module.exports = defineConfig({
56+
export default defineConfig({
5757
plugins: [splitVendorChunkPlugin()]
5858
})
5959
```
@@ -66,7 +66,7 @@ You can enable rollup watcher with `vite build --watch`. Or, you can directly ad
6666

6767
```js
6868
// vite.config.js
69-
module.exports = defineConfig({
69+
export default defineConfig({
7070
build: {
7171
watch: {
7272
// https://rollupjs.org/guide/en/#watch-options
@@ -97,10 +97,10 @@ During build, all you need to do is to specify multiple `.html` files as entry p
9797

9898
```js
9999
// vite.config.js
100-
const { resolve } = require('path')
101-
const { defineConfig } = require('vite')
100+
import { resolve } from 'path'
101+
import { defineConfig } from 'vite'
102102

103-
module.exports = defineConfig({
103+
export default defineConfig({
104104
build: {
105105
rollupOptions: {
106106
input: {
@@ -122,10 +122,10 @@ When it is time to bundle your library for distribution, use the [`build.lib` co
122122

123123
```js
124124
// vite.config.js
125-
const path = require('path')
126-
const { defineConfig } = require('vite')
125+
import { resolve } from 'path'
126+
import { defineConfig } from 'vite'
127127

128-
module.exports = defineConfig({
128+
export default defineConfig({
129129
build: {
130130
lib: {
131131
entry: path.resolve(__dirname, 'lib/main.js'),
@@ -214,17 +214,17 @@ experimental: {
214214
If the hashed assets and public files aren't deployed together, options for each group can be defined independently using asset `type` included in the third `context` param given to the function.
215215

216216
```js
217-
experimental: {
218-
renderBuiltUrl(filename: string, { hostType: 'js' | 'css' | 'html', type: 'public' | 'asset' }) {
219-
if (type === 'public') {
220-
return 'https://www.domain.com/' + filename
221-
}
222-
else if (path.extname(importer) === '.js') {
223-
return { runtime: `window.__assetsPath(${JSON.stringify(filename)})` }
224-
}
225-
else {
226-
return 'https://cdn.domain.com/assets/' + filename
227-
}
217+
experimental: {
218+
renderBuiltUrl(filename: string, { hostType: 'js' | 'css' | 'html', type: 'public' | 'asset' }) {
219+
if (type === 'public') {
220+
return 'https://www.domain.com/' + filename
221+
}
222+
else if (path.extname(importer) === '.js') {
223+
return { runtime: `window.__assetsPath(${JSON.stringify(filename)})` }
224+
}
225+
else {
226+
return 'https://cdn.domain.com/assets/' + filename
228227
}
229228
}
229+
}
230230
```

Diff for: ‎docs/guide/env-and-mode.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Vite exposes env variables on the special **`import.meta.env`** object. Some bui
1212

1313
- **`import.meta.env.DEV`**: {boolean} whether the app is running in development (always the opposite of `import.meta.env.PROD`)
1414

15+
- **`import.meta.env.SSR`**: {boolean} whether the app is running in the [server](./ssr.md#conditional-logic).
16+
1517
### Production Replacement
1618

1719
During production, these env variables are **statically replaced**. It is therefore necessary to always reference them using the full static string. For example, dynamic key access like `import.meta.env[key]` will not work.
@@ -47,12 +49,17 @@ Loaded env variables are also exposed to your client source code via `import.met
4749
To prevent accidentally leaking env variables to the client, only variables prefixed with `VITE_` are exposed to your Vite-processed code. e.g. the following file:
4850

4951
```
50-
DB_PASSWORD=foobar
5152
VITE_SOME_KEY=123
53+
DB_PASSWORD=foobar
5254
```
5355

5456
Only `VITE_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your client source code, but `DB_PASSWORD` will not.
5557

58+
```js
59+
console.log(import.meta.env.VITE_SOME_KEY) // 123
60+
console.log(import.meta.env.DB_PASSWORD) // undefined
61+
```
62+
5663
If you want to customize env variables prefix, see [envPrefix](/config/index#envprefix) option.
5764
5865
:::warning SECURITY NOTES

Diff for: ‎docs/guide/features.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ Vite provides first-class Vue support:
108108

109109
- Vue 3 SFC support via [@vitejs/plugin-vue](https://github.com/vitejs/vite/tree/main/packages/plugin-vue)
110110
- Vue 3 JSX support via [@vitejs/plugin-vue-jsx](https://github.com/vitejs/vite/tree/main/packages/plugin-vue-jsx)
111-
- Vue 2 support via [underfin/vite-plugin-vue2](https://github.com/underfin/vite-plugin-vue2)
111+
- Vue 2.7 support via [vitejs/vite-plugin-vue2](https://github.com/vitejs/vite-plugin-vue2)
112+
- Vue <2.7 support via [underfin/vite-plugin-vue2](https://github.com/underfin/vite-plugin-vue2)
112113

113114
## JSX
114115

115-
`.jsx` and `.tsx` files are also supported out of the box. JSX transpilation is also handled via [esbuild](https://esbuild.github.io), and defaults to the React 16 flavor. React 17 style JSX support in esbuild is tracked [here](https://github.com/evanw/esbuild/issues/334).
116+
`.jsx` and `.tsx` files are also supported out of the box. JSX transpilation is also handled via [esbuild](https://esbuild.github.io).
116117

117118
Vue users should use the official [@vitejs/plugin-vue-jsx](https://github.com/vitejs/vite/tree/main/packages/plugin-vue-jsx) plugin, which provides Vue 3 specific features including HMR, global component resolving, directives and slots.
118119

Diff for: ‎docs/guide/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ You can learn more about the rationale behind the project in the [Why Vite](./wh
1818

1919
## Browser Support
2020

21-
- The default build targets browsers that support both [native ES Modules](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import). Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) - see the [Building for Production](./build) section for more details.
21+
The default build targets browsers that support both [native ES Modules](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import). Legacy browsers can be supported via the official [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) - see the [Building for Production](./build) section for more details.
2222

2323
## Trying Vite Online
2424

Diff for: ‎docs/guide/migration.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ A small fraction of users will now require using [@vitejs/plugin-legacy](https:/
1717

1818
## Config Options Changes
1919

20-
- The following options that were already deprecated in v2 have been removed:
20+
The following options that were already deprecated in v2 have been removed:
2121

22-
- `alias` (switch to [`resolve.alias`](../config/shared-options.md#resolve-alias))
23-
- `dedupe` (switch to [`resolve.dedupe`](../config/shared-options.md#resolve-dedupe))
24-
- `build.base` (switch to [`base`](../config/shared-options.md#base))
25-
- `build.brotliSize` (switch to [`build.reportCompressedSize`](../config/build-options.md#build-reportcompressedsize))
26-
- `build.cleanCssOptions` (Vite now uses esbuild for CSS minification)
27-
- `build.polyfillDynamicImport` (use [`@vitejs/plugin-legacy`](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) for browsers without dynamic import support)
28-
- `optimizeDeps.keepNames` (switch to [`optimizeDeps.esbuildOptions.keepNames`](../config/dep-optimization-options.md#optimizedeps-esbuildoptions))
22+
- `alias` (switch to [`resolve.alias`](../config/shared-options.md#resolve-alias))
23+
- `dedupe` (switch to [`resolve.dedupe`](../config/shared-options.md#resolve-dedupe))
24+
- `build.base` (switch to [`base`](../config/shared-options.md#base))
25+
- `build.brotliSize` (switch to [`build.reportCompressedSize`](../config/build-options.md#build-reportcompressedsize))
26+
- `build.cleanCssOptions` (Vite now uses esbuild for CSS minification)
27+
- `build.polyfillDynamicImport` (use [`@vitejs/plugin-legacy`](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) for browsers without dynamic import support)
28+
- `optimizeDeps.keepNames` (switch to [`optimizeDeps.esbuildOptions.keepNames`](../config/dep-optimization-options.md#optimizedeps-esbuildoptions))
2929

30-
## Architecture changes and legacy Options
30+
## Architecture Changes and Legacy Options
3131

3232
This section describes the biggest architecture changes in Vite v3. To allow projects to migrate from v2 in case of a compat issue, legacy options have been added to revert to the Vite v2 strategies.
3333

@@ -72,7 +72,7 @@ Also [`build.rollupOptions.output.inlineDynamicImports`](https://rollupjs.org/gu
7272
- When using an alias with `import.meta.glob`, the keys are always absolute.
7373
- `import.meta.globEager` is now deprecated. Use `import.meta.glob('*', { eager: true })` instead.
7474

75-
### WebAssembly support
75+
### WebAssembly Support
7676

7777
`import init from 'example.wasm'` syntax is dropped to prevent future collision with ["ESM integration for Wasm"](https://github.com/WebAssembly/esm-integration).
7878
You can use `?init` which is similar to the previous behavior.
@@ -87,7 +87,7 @@ You can use `?init` which is similar to the previous behavior.
8787
})
8888
```
8989

90-
### Automatic https certificate generation
90+
### Automatic https Certificate Generation
9191

9292
A valid certificate is needed when using `https`. In Vite v2, if no certificate was configured, a self-signed certificate was automatically created and cached.
9393
Since Vite v3, we recommend manually creating your certificates. If you still want to use the automatic generation from v2, this feature can be enabled back by adding [@vitejs/plugin-basic-ssl](https://github.com/vitejs/vite-plugin-basic-ssl) to the project plugins.

Diff for: ‎docs/guide/ssr.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ When building an SSR app, you likely want to have full control over your main se
6666
**server.js**
6767
6868
```js{17-19}
69-
const fs = require('fs')
70-
const path = require('path')
71-
const express = require('express')
72-
const { createServer: createViteServer } = require('vite')
69+
import fs from 'fs'
70+
import path from 'path'
71+
import express from 'express'
72+
import {createServer as createViteServer} from 'vite'
7373

7474
async function createServer() {
7575
const app = express()
@@ -154,7 +154,7 @@ The `dev` script in `package.json` should also be changed to use the server scri
154154
To ship an SSR project for production, we need to:
155155
156156
1. Produce a client build as normal;
157-
2. Produce an SSR build, which can be directly loaded via `require()` so that we don't have to go through Vite's `ssrLoadModule`;
157+
2. Produce an SSR build, which can be directly loaded via `import()` so that we don't have to go through Vite's `ssrLoadModule`;
158158
159159
Our scripts in `package.json` will look like this:
160160
@@ -174,7 +174,7 @@ Then, in `server.js` we need to add some production specific logic by checking `
174174
175175
- Instead of reading the root `index.html`, use the `dist/client/index.html` as the template instead, since it contains the correct asset links to the client build.
176176
177-
- Instead of `await vite.ssrLoadModule('/src/entry-server.js')`, use `require('./dist/server/entry-server.js')` instead (this file is the result of the SSR build).
177+
- Instead of `await vite.ssrLoadModule('/src/entry-server.js')`, use `import('./dist/server/entry-server.js')` instead (this file is the result of the SSR build).
178178
179179
- Move the creation and all usage of the `vite` dev server behind dev-only conditional branches, then add static file serving middlewares to serve files from `dist/client`.
180180

Diff for: ‎docs/guide/static-deploy.md

+31-65
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ The following guides are based on some shared assumptions:
1818
It is important to note that `vite preview` is intended for previewing the build locally and not meant as a production server.
1919

2020
::: tip NOTE
21-
These guides provide instructions for performing a static deployment of your Vite site. Vite also has experimental support for Server Side Rendering. SSR refers to front-end frameworks that support running the same application in Node.js, pre-rendering it to HTML, and finally hydrating it on the client. Check out the [SSR Guide](./ssr) to learn about this feature. On the other hand, if you are looking for integration with traditional server-side frameworks, check out the [Backend Integration guide](./backend-integration) instead.
21+
These guides provide instructions for performing a static deployment of your Vite site. Vite also supports Server Side Rendering. SSR refers to front-end frameworks that support running the same application in Node.js, pre-rendering it to HTML, and finally hydrating it on the client. Check out the [SSR Guide](./ssr) to learn about this feature. On the other hand, if you are looking for integration with traditional server-side frameworks, check out the [Backend Integration guide](./backend-integration) instead.
2222
:::
2323

24-
## Building The App
24+
## Building the App
2525

2626
You may run `npm run build` command to build the app.
2727

@@ -31,7 +31,7 @@ $ npm run build
3131

3232
By default, the build output will be placed at `dist`. You may deploy this `dist` folder to any of your preferred platforms.
3333

34-
### Testing The App Locally
34+
### Testing the App Locally
3535

3636
Once you've built the app, you may test it locally by running `npm run preview` command.
3737

@@ -52,7 +52,7 @@ You may configure the port of the server by passing `--port` flag as an argument
5252
}
5353
```
5454

55-
Now the `preview` method will launch the server at `http://localhost:8080`.
55+
Now the `preview` command will launch the server at `http://localhost:8080`.
5656

5757
## GitHub Pages
5858

@@ -97,40 +97,6 @@ Now the `preview` method will launch the server at `http://localhost:8080`.
9797
You can also run the above script in your CI setup to enable automatic deployment on each push.
9898
:::
9999

100-
### GitHub Pages and Travis CI
101-
102-
1. Set the correct `base` in `vite.config.js`.
103-
104-
If you are deploying to `https://<USERNAME or GROUP>.github.io/`, you can omit `base` as it defaults to `'/'`.
105-
106-
If you are deploying to `https://<USERNAME or GROUP>.github.io/<REPO>/`, for example your repository is at `https://github.com/<USERNAME>/<REPO>`, then set `base` to `'/<REPO>/'`.
107-
108-
2. Create a file named `.travis.yml` in the root of your project.
109-
110-
3. Run `npm install` locally and commit the generated lockfile (`package-lock.json`).
111-
112-
4. Use the GitHub Pages deploy provider template, and follow the [Travis CI documentation](https://docs.travis-ci.com/user/deployment/pages/).
113-
114-
```yaml
115-
language: node_js
116-
node_js:
117-
- lts/*
118-
install:
119-
- npm ci
120-
script:
121-
- npm run build
122-
deploy:
123-
provider: pages
124-
skip_cleanup: true
125-
local_dir: dist
126-
# A token generated on GitHub allowing Travis to push code on you repository.
127-
# Set in the Travis settings page of your repository, as a secure variable.
128-
github_token: $GITHUB_TOKEN
129-
keep_history: true
130-
on:
131-
branch: main
132-
```
133-
134100
## GitLab Pages and GitLab CI
135101

136102
1. Set the correct `base` in `vite.config.js`.
@@ -187,6 +153,33 @@ The Netlify CLI will share with you a preview URL to inspect. When you are ready
187153
$ ntl deploy --prod
188154
```
189155

156+
## Vercel
157+
158+
### Vercel CLI
159+
160+
1. Install the [Vercel CLI](https://vercel.com/cli) and run `vercel` to deploy.
161+
2. Vercel will detect that you are using Vite and will enable the correct settings for your deployment.
162+
3. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))
163+
164+
```bash
165+
$ npm i -g vercel
166+
$ vercel init vite
167+
Vercel CLI
168+
> Success! Initialized "vite" example in ~/your-folder.
169+
- To deploy, `cd vite` and run `vercel`.
170+
```
171+
172+
### Vercel for Git
173+
174+
1. Push your code to your git repository (GitHub, GitLab, Bitbucket).
175+
2. [Import your Vite project](https://vercel.com/new) into Vercel.
176+
3. Vercel will detect that you are using Vite and will enable the correct settings for your deployment.
177+
4. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))
178+
179+
After your project has been imported and deployed, all subsequent pushes to branches will generate [Preview Deployments](https://vercel.com/docs/concepts/deployments/environments#preview), and all changes made to the Production Branch (commonly “main”) will result in a [Production Deployment](https://vercel.com/docs/concepts/deployments/environments#production).
180+
181+
Learn more about Vercel’s [Git Integration](https://vercel.com/docs/concepts/git).
182+
190183
## Cloudflare Pages
191184

192185
### Cloudflare Pages via Wrangler
@@ -325,33 +318,6 @@ You can also deploy to a [custom domain](http://surge.sh/help/adding-a-custom-do
325318
$ heroku open
326319
```
327320

328-
## Vercel
329-
330-
### Vercel CLI
331-
332-
1. Install the [Vercel CLI](https://vercel.com/cli) and run `vercel` to deploy.
333-
2. Vercel will detect that you are using Vite and will enable the correct settings for your deployment.
334-
3. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))
335-
336-
```bash
337-
$ npm i -g vercel
338-
$ vercel init vite
339-
Vercel CLI
340-
> Success! Initialized "vite" example in ~/your-folder.
341-
- To deploy, `cd vite` and run `vercel`.
342-
```
343-
344-
### Vercel for Git
345-
346-
1. Push your code to your git repository (GitHub, GitLab, Bitbucket).
347-
2. [Import your Vite project](https://vercel.com/new) into Vercel.
348-
3. Vercel will detect that you are using Vite and will enable the correct settings for your deployment.
349-
4. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))
350-
351-
After your project has been imported and deployed, all subsequent pushes to branches will generate [Preview Deployments](https://vercel.com/docs/concepts/deployments/environments#preview), and all changes made to the Production Branch (commonly “main”) will result in a [Production Deployment](https://vercel.com/docs/concepts/deployments/environments#production).
352-
353-
Learn more about Vercel’s [Git Integration](https://vercel.com/docs/concepts/git).
354-
355321
## Azure Static Web Apps
356322

357323
You can quickly deploy your Vite app with Microsoft Azure [Static Web Apps](https://aka.ms/staticwebapps) service. You need:

Diff for: ‎packages/plugin-legacy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Run `node --input-type=module -e "import {cspHashes} from '@vitejs/plugin-legacy
163163
These values (without the `sha256-` prefix) can also be retrieved via
164164

165165
```js
166-
const { cspHashes } = require('@vitejs/plugin-legacy')
166+
import { cspHashes } from '@vitejs/plugin-legacy'
167167
```
168168

169169
When using the `regenerator-runtime` polyfill, it will attempt to use the `globalThis` object to register itself. If `globalThis` is not available (it is [fairly new](https://caniuse.com/?search=globalThis) and not widely supported, including IE 11), it attempts to perform dynamic `Function(...)` call which violates the CSP. To avoid dynamic `eval` in the absence of `globalThis` consider adding `core-js/proposals/global-this` to `additionalLegacyPolyfills` to define it.

Diff for: ‎packages/plugin-vue/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export default {
110110

111111
```ts
112112
import vue from '@vitejs/plugin-vue'
113+
import yaml from 'js-yaml'
113114

114115
const vueI18nPlugin = {
115116
name: 'vue-i18n',
@@ -118,7 +119,7 @@ const vueI18nPlugin = {
118119
return
119120
}
120121
if (/\.ya?ml$/.test(id)) {
121-
code = JSON.stringify(require('js-yaml').load(code.trim()))
122+
code = JSON.stringify(yaml.load(code.trim()))
122123
}
123124
return `export default Comp => {
124125
Comp.i18n = ${code}

0 commit comments

Comments
 (0)
Please sign in to comment.