Skip to content

Commit f2c869d

Browse files
authored
docs: improve migration from v2 guide (#8417)
1 parent cfc37ac commit f2c869d

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

docs/guide/migration.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ A small fraction of users will now require using [@vitejs/plugin-legacy](https:/
1919

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

22-
- `optimizeDeps.keepNames` (switch to [`optimizeDeps.esbuildOptions.keepNames`](../config/dep-optimization-options.md#optimizedepsesbuildoptions))
23-
- `build.base` (switch to [`base`](../config/shared-options.md#base))
2422
- `alias` (switch to [`resolve.alias`](../config/shared-options.md#resolvealias))
2523
- `dedupe` (switch to [`resolve.dedupe`](../config/shared-options.md#resolvededupe))
26-
- `polyfillDynamicImport` (use [`@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) for browsers without dynamic import support)
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#optimizedepsesbuildoptions))
2729

2830
## Dev Server Changes
2931

32+
Vite's default dev server port is now 5173. You can use [`server.port`](../config/server-options.md#server-port) to set it to 3000.
33+
3034
Vite optimizes dependencies with esbuild to both convert CJS-only deps to ESM and to reduce the number of modules the browser needs to request. In v3, the default strategy to discover and batch dependencies has changed. Vite no longer pre-scans user code with esbuild to get an initial list of dependencies on cold start. Instead, it delays the first dependency optimization run until every imported user module on load is processed.
3135

3236
To get back the v2 strategy, you can use [`optimizeDeps.devScan`](../config/dep-optimization-options.md#optimizedepsdevscan).
@@ -45,9 +49,41 @@ If using ESM for SSR isn't possible in your project, you can set `ssr.format: 'c
4549

4650
## General Changes
4751

52+
- JS file extensions in SSR and lib mode now use a valid extension (`js`, `mjs`, or `cjs`) for output JS entries and chunks based on their format and the package type.
53+
54+
### `import.meta.glob`
55+
4856
- [Raw `import.meta.glob`](features.md#glob-import-as) switched from `{ assert: { type: 'raw' }}` to `{ as: 'raw' }`
57+
- Keys of `import.meta.glob` are now relative to the current module.
4958

50-
- JS file extensions in SSR and lib mode now use a valid extension (`js`, `mjs`, or `cjs`) for output JS entries and chunks based on their format and the package type.
59+
```diff
60+
// file: /foo/index.js
61+
const modules = import.meta.glob('../foo/*.js')
62+
63+
// transformed:
64+
const modules = {
65+
- '../foo/bar.js': () => {}
66+
+ './bar.js': () => {}
67+
}
68+
```
69+
70+
- When using an alias with `import.meta.glob`, the keys are always absolute.
71+
- `import.meta.globEager` is now deprecated. Use `import.meta.glob('*', { eager: true })` instead.
72+
73+
### WebAssembly support
74+
75+
`import init from 'example.wasm'` syntax is dropped to prevent future collision with ["ESM integration for Wasm"](https://github.com/WebAssembly/esm-integration).
76+
You can use `?init` which is similar to the previous behavior.
77+
78+
```diff
79+
-import init from 'example.wasm'
80+
+import init from 'example.wasm?init'
81+
82+
-init().then((instance) => {
83+
+init().then(({ exports }) => {
84+
exports.test()
85+
})
86+
```
5187

5288
## Migration from v1
5389

0 commit comments

Comments
 (0)