You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/api-plugin.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Vite strives to offer established patterns out of the box, so before creating a
11
11
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).
12
12
13
13
::: 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).
Copy file name to clipboardExpand all lines: docs/guide/assets.md
-4
Original file line number
Diff line number
Diff line change
@@ -113,7 +113,3 @@ const imgUrl = new URL(imagePath, import.meta.url).href
113
113
::: warning Does not work with SSR
114
114
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.
115
115
:::
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`.
@@ -53,7 +53,7 @@ You can configure how chunks are split using `build.rollupOptions.output.manualC
53
53
```js
54
54
// vite.config.js
55
55
import { splitVendorChunkPlugin } from'vite'
56
-
module.exports=defineConfig({
56
+
exportdefaultdefineConfig({
57
57
plugins: [splitVendorChunkPlugin()]
58
58
})
59
59
```
@@ -66,7 +66,7 @@ You can enable rollup watcher with `vite build --watch`. Or, you can directly ad
66
66
67
67
```js
68
68
// vite.config.js
69
-
module.exports=defineConfig({
69
+
exportdefaultdefineConfig({
70
70
build: {
71
71
watch: {
72
72
// 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
97
97
98
98
```js
99
99
// vite.config.js
100
-
const { resolve } =require('path')
101
-
const { defineConfig } =require('vite')
100
+
import { resolve } from'path'
101
+
import { defineConfig } from'vite'
102
102
103
-
module.exports=defineConfig({
103
+
exportdefaultdefineConfig({
104
104
build: {
105
105
rollupOptions: {
106
106
input: {
@@ -122,10 +122,10 @@ When it is time to bundle your library for distribution, use the [`build.lib` co
122
122
123
123
```js
124
124
// vite.config.js
125
-
constpath=require('path')
126
-
const { defineConfig } =require('vite')
125
+
import { resolve } from'path'
126
+
import { defineConfig } from'vite'
127
127
128
-
module.exports=defineConfig({
128
+
exportdefaultdefineConfig({
129
129
build: {
130
130
lib: {
131
131
entry:path.resolve(__dirname, 'lib/main.js'),
@@ -214,17 +214,17 @@ experimental: {
214
214
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.
Copy file name to clipboardExpand all lines: docs/guide/env-and-mode.md
+8-1
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,8 @@ Vite exposes env variables on the special **`import.meta.env`** object. Some bui
12
12
13
13
-**`import.meta.env.DEV`**: {boolean} whether the app is running in development (always the opposite of `import.meta.env.PROD`)
14
14
15
+
-**`import.meta.env.SSR`**: {boolean} whether the app is running in the [server](./ssr.md#conditional-logic).
16
+
15
17
### Production Replacement
16
18
17
19
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
47
49
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:
48
50
49
51
```
50
-
DB_PASSWORD=foobar
51
52
VITE_SOME_KEY=123
53
+
DB_PASSWORD=foobar
52
54
```
53
55
54
56
Only `VITE_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your client source code, but `DB_PASSWORD` will not.
Copy file name to clipboardExpand all lines: docs/guide/features.md
+3-2
Original file line number
Diff line number
Diff line change
@@ -108,11 +108,12 @@ Vite provides first-class Vue support:
108
108
109
109
- Vue 3 SFC support via [@vitejs/plugin-vue](https://github.com/vitejs/vite/tree/main/packages/plugin-vue)
110
110
- 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)
112
113
113
114
## JSX
114
115
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).
116
117
117
118
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.
Copy file name to clipboardExpand all lines: docs/guide/index.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ You can learn more about the rationale behind the project in the [Why Vite](./wh
18
18
19
19
## Browser Support
20
20
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.
Copy file name to clipboardExpand all lines: docs/guide/migration.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -17,17 +17,17 @@ A small fraction of users will now require using [@vitejs/plugin-legacy](https:/
17
17
18
18
## Config Options Changes
19
19
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:
21
21
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))
29
29
30
-
## Architecture changes and legacy Options
30
+
## Architecture Changes and Legacy Options
31
31
32
32
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.
33
33
@@ -72,7 +72,7 @@ Also [`build.rollupOptions.output.inlineDynamicImports`](https://rollupjs.org/gu
72
72
- When using an alias with `import.meta.glob`, the keys are always absolute.
73
73
-`import.meta.globEager` is now deprecated. Use `import.meta.glob('*', { eager: true })` instead.
74
74
75
-
### WebAssembly support
75
+
### WebAssembly Support
76
76
77
77
`import init from 'example.wasm'` syntax is dropped to prevent future collision with ["ESM integration for Wasm"](https://github.com/WebAssembly/esm-integration).
78
78
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.
87
87
})
88
88
```
89
89
90
-
### Automatic https certificate generation
90
+
### Automatic https Certificate Generation
91
91
92
92
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.
93
93
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.
@@ -154,7 +154,7 @@ The `dev` script in `package.json` should also be changed to use the server scri
154
154
To ship an SSR project for production, we need to:
155
155
156
156
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`;
158
158
159
159
Our scripts in `package.json` will look like this:
160
160
@@ -174,7 +174,7 @@ Then, in `server.js` we need to add some production specific logic by checking `
174
174
175
175
- 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.
176
176
177
-
- Instead of `awaitvite.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 `awaitvite.ssrLoadModule('/src/entry-server.js')`, use `import('./dist/server/entry-server.js')` instead (this file is the result of the SSR build).
178
178
179
179
- 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`.
0 commit comments