Skip to content

Commit

Permalink
docs: migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 2, 2021
1 parent 7d8a03d commit 3a27fa3
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 4 deletions.
8 changes: 5 additions & 3 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default defineConfig({
If the config needs to conditional determine options based on the command (`serve` or `build`) or the [mode](/guide/env-and-mode) being used, it can export a function instead:

```js
export default (({ command, mode }) => {
export default ({ command, mode }) => {
if (command === 'serve') {
return {
// serve specific config
Expand All @@ -61,7 +61,7 @@ export default (({ command, mode }) => {
// build specific config
}
}
})
}
```

## Shared Options
Expand Down Expand Up @@ -192,10 +192,12 @@ export default (({ command, mode }) => {

### server.https

- **Type:** `boolean`
- **Type:** `boolean | https.ServerOptions`

Enable TLS + HTTP/2. Note this downgrades to TLS only when the [`server.proxy` option](#server-proxy) is also used.

The value can also be an [options object](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) passed to `https.createServer()`.

### server.open

- **Type:** `boolean`
Expand Down
121 changes: 120 additions & 1 deletion docs/guide/migration.md
Original file line number Diff line number Diff line change
@@ -1 +1,120 @@
# Migration from v1
# Migration from v1

## Config Options Change

- The following options have been removed and should be implemented via [plugins](./api-plugin):

- `resolvers`
- `transforms`
- `indexHtmlTransforms`

- `jsx` and `enableEsbuild` have been removed; Use the new [`esbuild`](/config/#esbuild) option instead.

- [CSS related options](/config/#css-modules) are now nested under `css`.

- All [build-specific options](/config/#build-options) are now nested under `build`.

- `rollupInputOptions` and `rollupOutputOptions` are replaced by [`build.rollupOptions`](/config/#build-rollupoptions).
- `esbuildTarget` is now [`build.target`](/config/#build-target).
- `emitManifest` is now [`build.manifest`](/config/#build-manifest).
- The following build options have been removed since they can be achieved via plugin hooks or other options:
- `entry`
- `rollupDedupe`
- `emitAssets`
- `emitIndex`
- `shouldPreload`
- `configureBuild`

- All [server-specific options](/config/#server-options) are now nested under
`server`.

- `hostname` is now [`server.host`](/config/#server-host).
- `httpsOptions` has been removed. [`server.https`](/config/#server-https) can diretly accept the options object.
- `chokidarWatchOptions` is now [`server.watch`](/config/#server-watch).

- [`assetsInclude`](/config/#assetsInclude) now expects `string | RegExp | (string | RegExp)[]` instead of a function.

- All Vue specific options are removed; Pass options to the Vue plugin instead.

## Vue Support

Vite 2.0 core is now framework agnostic. Vue support is now provided via [`@vitejs/plugin-vue`](https://github.com/vitejs/vite/tree/master/packages/plugin-vue). Simply install it and add it in the Vite config:

```js
import vue from '@vitejs/plugin-vue'

export default {
plugins: [vue()]
}
```

### Custom Blocks Transforms

A custom plugin can be used to transform Vue custom blocks like the one below:

```ts
// vite.config.js
import vue from '@vitejs/plugin-vue'

const vueI18nPlugin = {
name: 'vue-i18n',
transform(code, id) {
if (!/vue&type=i18n/.test(id)) {
return
}
if (/\.ya?ml$/.test(id)) {
code = JSON.stringify(require('js-yaml').safeLoad(code.trim()))
}
return `export default Comp => {
Comp.i18n = ${code}
}`
}
}

export default {
plugins: [vue(), vueI18nPlugin]
}
```

## React Support

React Fast Refresh support is now provided via [`@vitejs/plugin-react-refresh`](https://github.com/vitejs/vite/tree/master/packages/plugin-react-refresh).

## HMR API Change

`import.meta.hot.acceptDeps()` have been deprecated. [`import.meta.hot.accept()`](./api-hmr#hot-accept-deps-cb) can now accept single or multiple deps.

## Manifest Format Change

The build manifest now uses the following format:

```json
{
"index.js": {
"file": "assets/index.acaf2b48.js",
"imports": [...]
},
"index.css": {
"file": "assets/index.7b7dbd85.css"
}
"asset.png": {
"file": "assets/asset.0ab0f9cd.png"
}
}
```

For entry JS chunks, it also lists its imported chunks which can be used to render preload directives.

## For Plugin Authors

Vite 2 uses a completely redesigned plugin interface which extends Rollup plugins. Please read the new [Plugin Development Guide](./api-plugin).

Some general pointers on migrating a v1 plugin to v2:

- `resolvers` -> use the [`resolveId`](https://rollupjs.org/guide/en/#resolveid) hook
- `transforms` -> use the [`transform`](https://rollupjs.org/guide/en/#transform) hook
- `indexHtmlTransforms` -> use the [`transformIndexHtml`](./api-plugin#transformindexhtml) hook
- Serving virtual files -> use [`resolveId`](https://rollupjs.org/guide/en/#resolveid) + [`load`](https://rollupjs.org/guide/en/#load) hooks
- Adding `alias`, `define` or other config options -> use the [`config`](./api-plugin#config) hook

Since most of the logic should be done via plugin hooks instead of middlewares, the need for middlewares are greatly reduced. The ineternal server app is now a good old [connect](https://github.com/senchalabs/connect) instance instead of Koa.
17 changes: 17 additions & 0 deletions packages/plugin-vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ export default {
}
```

## Options

```ts
export interface Options {
include?: string | RegExp | (string | RegExp)[]
exclude?: string | RegExp | (string | RegExp)[]

ssr?: boolean
isProduction?: boolean

// options to pass on to @vue/compiler-sfc
script?: SFCScriptCompileOptions
template?: SFCTemplateCompileOptions
style?: SFCStyleCompileOptions
}
```

## Example for transforming custom blocks

```ts
Expand Down

0 comments on commit 3a27fa3

Please sign in to comment.