Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jun 13, 2022
2 parents 828ac06 + 2548dd3 commit 1ed902b
Show file tree
Hide file tree
Showing 208 changed files with 3,208 additions and 1,712 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export default defineConfig({
link: '/guide/comparisons'
},
{
text: 'Migration from v1',
text: 'Migration from v2',
link: '/guide/migration'
}
]
Expand Down
6 changes: 6 additions & 0 deletions docs/config/build-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ Set to `false` to disable minification, or specify the minifier to use. The defa

Note the `build.minify` option is not available when using the `'es'` format in lib mode.

Terser must be installed when it is set to `'terser'`.

```sh
npm add -D terser
```

## build.terserOptions

- **Type:** `TerserOptions`
Expand Down
10 changes: 5 additions & 5 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ vite --config my-config.js
```

::: tip NOTE
Vite will replace `__filename`, `__dirname`, and `import.meta.url` in config files and its deps. Using these as variable names or passing as a parameter to a function with string double quote (example `console.log`) will result in an error:
Vite will inject `__filename`, `__dirname` in config files and its deps. Declaring these variables at top level will result in an error:

```js
const __filename = "value"
// will be transformed to
const "path/vite.config.js" = "value"
const __filename = 'value' // SyntaxError: Identifier '__filename' has already been declared

console.log("import.meta.url") // break error on build
const func = () => {
const __filename = 'value' // no error
}
```

:::
Expand Down
11 changes: 10 additions & 1 deletion docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Vite only performs transpilation on `.ts` files and does **NOT** perform type ch

Vite uses [esbuild](https://github.com/evanw/esbuild) to transpile TypeScript into JavaScript which is about 20~30x faster than vanilla `tsc`, and HMR updates can reflect in the browser in under 50ms.

Use the [Type-Only Imports and Export](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) syntax to avoid potential problems like type-only imports being incorrectly bundled. for example:
Use the [Type-Only Imports and Export](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export) syntax to avoid potential problems like type-only imports being incorrectly bundled, for example:

```ts
import type { T } from 'only/types'
Expand Down Expand Up @@ -210,6 +210,15 @@ Vite improves `@import` resolving for Sass and Less so that Vite aliases are als

You can also use CSS modules combined with pre-processors by prepending `.module` to the file extension, for example `style.module.scss`.

### Disabling CSS injection into the page

The automatic injection of CSS contents can be turned off via the `?inline` query parameter. In this case, the processed CSS string is returned as the module's default export as usual, but the styles aren't injected to the page.

```js
import styles from './foo.css' // will be injected into the page
import otherStyles from './bar.css?inline' // will not be injected into the page
```

## Static Assets

Importing a static asset will return the resolved public URL when it is served:
Expand Down
176 changes: 78 additions & 98 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
@@ -1,133 +1,113 @@
# Migration from v1
# Migration from v2

## Config Options Change
## Node Support

- The following options have been removed and should be implemented via [plugins](./api-plugin):
Vite no longer supports Node v12, which reached its EOL. Node 14.6+ is now required.

- `resolvers`
- `transforms`
- `indexHtmlTransforms`
## Modern Browser Baseline change

- `jsx` and `enableEsbuild` have been removed; Use the new [`esbuild`](/config/#esbuild) option instead.
The production bundle assumes support for modern JavaScript. By default, Vite targets browsers which support the [native ES Modules](https://caniuse.com/es6-module) and [native ESM dynamic import](https://caniuse.com/es6-module-dynamic-import) and [`import.meta`](https://caniuse.com/mdn-javascript_statements_import_meta):

- [CSS related options](/config/#css-modules) are now nested under `css`.
- Chrome >=87
- Firefox >=78
- Safari >=13
- Edge >=88

- All [build-specific options](/config/#build-options) are now nested under `build`.
A small fraction of users will now require using [@vitejs/plugin-legacy](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy), which will automatically generate legacy chunks and corresponding ES language feature polyfills.

- `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`
## Config Options Changes

- All [server-specific options](/config/#server-options) are now nested under
`server`.
- The following options that were already deprecated in v2 have been removed:

- `hostname` is now [`server.host`](/config/#server-host).
- `httpsOptions` has been removed. [`server.https`](/config/#server-https) can directly accept the options object.
- `chokidarWatchOptions` is now [`server.watch`](/config/#server-watch).
- `alias` (switch to [`resolve.alias`](../config/shared-options.md#resolvealias))
- `dedupe` (switch to [`resolve.dedupe`](../config/shared-options.md#resolvededupe))
- `build.base` (switch to [`base`](../config/shared-options.md#base))
- `build.brotliSize` (switch to [`build.reportCompressedSize`](../config/build-options.md#build-reportcompressedsize))
- `build.cleanCssOptions` (Vite now uses esbuild for CSS minification)
- `build.polyfillDynamicImport` (use [`@vitejs/plugin-legacy`](https://github.com/vitejs/vite/tree/main/packages/plugin-legacy) for browsers without dynamic import support)
- `optimizeDeps.keepNames` (switch to [`optimizeDeps.esbuildOptions.keepNames`](../config/dep-optimization-options.md#optimizedepsesbuildoptions))

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

- All Vue specific options are removed; Pass options to the Vue plugin instead.
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.

## Alias Behavior Change
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.

[`alias`](/config/#resolve-alias) is now being passed to `@rollup/plugin-alias` and no longer require start/ending slashes. The behavior is now a direct replacement, so 1.0-style directory alias key should remove the ending slash:
To get back the v2 strategy, you can use [`optimizeDeps.devScan`](../config/dep-optimization-options.md#optimizedepsdevscan).

```diff
- alias: { '/@foo/': path.resolve(__dirname, 'some-special-dir') }
+ alias: { '/@foo': path.resolve(__dirname, 'some-special-dir') }
```
## Build Changes

Alternatively, you can use the `[{ find: RegExp, replacement: string }]` option format for more precise control.
In v3, Vite uses esbuild to optimize dependencies by default. Doing so, it removes one of the most significant differences between dev and prod present in v2. Because esbuild converts CJS-only dependencies to ESM, [`@rollupjs/plugin-commonjs`](https://github.com/rollup/plugins/tree/master/packages/commonjs) is no longer used.

## Vue Support
If you need to get back to the v2 strategy, you can use [`optimizeDeps.disabled: 'build'`](../config/dep-optimization-options.md#optimizedepsdisabled).

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

```js
import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
Vite v3 uses ESM for the SSR build by default. When using ESM, the [SSR externalization heuristics](https://vitejs.dev/guide/ssr.html#ssr-externals) are no longer needed. By default, all dependencies are externalized. You can use [`ssr.noExternal`](../config/ssr-options.md#ssrnoexternal) to control what dependencies to include in the SSR bundle.

export default defineConfig({
plugins: [vue()]
})
```
If using ESM for SSR isn't possible in your project, you can set `ssr.format: 'cjs'` to generate a CJS bundle. In this case, the same externalization strategy of Vite v2 will be used.

### 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'
import { defineConfig } from 'vite'

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').load(code.trim()))
}
return `export default Comp => {
Comp.i18n = ${code}
}`
}
}
## General Changes

export default defineConfig({
plugins: [vue(), vueI18nPlugin]
})
```
- 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.

## React Support
### `import.meta.glob`

React Fast Refresh support is now provided via [`@vitejs/plugin-react`](https://github.com/vitejs/vite/tree/main/packages/plugin-react).
- [Raw `import.meta.glob`](features.md#glob-import-as) switched from `{ assert: { type: 'raw' }}` to `{ as: 'raw' }`
- Keys of `import.meta.glob` are now relative to the current module.

## HMR API Change
```diff
// file: /foo/index.js
const modules = import.meta.glob('../foo/*.js')

`import.meta.hot.acceptDeps()` have been deprecated. [`import.meta.hot.accept()`](./api-hmr#hot-accept-deps-cb) can now accept single or multiple deps.
// transformed:
const modules = {
- '../foo/bar.js': () => {}
+ './bar.js': () => {}
}
```

## Manifest Format Change
- When using an alias with `import.meta.glob`, the keys are always absolute.
- `import.meta.globEager` is now deprecated. Use `import.meta.glob('*', { eager: true })` instead.

The build manifest now uses the following format:
### WebAssembly support

```json
{
"index.js": {
"file": "assets/index.acaf2b48.js",
"imports": [...]
},
"index.css": {
"file": "assets/index.7b7dbd85.css"
}
"asset.png": {
"file": "assets/asset.0ab0f9cd.png"
}
}
`import init from 'example.wasm'` syntax is dropped to prevent future collision with ["ESM integration for Wasm"](https://github.com/WebAssembly/esm-integration).
You can use `?init` which is similar to the previous behavior.

```diff
-import init from 'example.wasm'
+import init from 'example.wasm?init'

-init().then((instance) => {
+init().then(({ exports }) => {
exports.test()
})
```

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

There are some changes which only affects plugin/tool creators.

## For Plugin Authors
- [[#5868] refactor: remove deprecated api for 3.0](https://github.com/vitejs/vite/pull/5868)
- `printHttpServerUrls` is removed
- `server.app`, `server.transformWithEsbuild` are removed
- `import.meta.hot.acceptDeps` is removed
- [[#7995] chore: do not fixStacktrace](https://github.com/vitejs/vite/pull/7995)
- `ssrLoadModule`'s `fixStacktrace` option's default is now `false`
- [[#8178] feat!: migrate to ESM](https://github.com/vitejs/vite/pull/8178)
- `formatPostcssSourceMap` is now async
- `resolvePackageEntry`, `resolvePackageData` are no longer available from CJS build (dynamic import is needed to use in CJS)

Vite 2 uses a completely redesigned plugin interface which extends Rollup plugins. Please read the new [Plugin Development Guide](./api-plugin).
Also there are other breaking changes which only affect few users.

Some general pointers on migrating a v1 plugin to v2:
- [[#5018] feat: enable `generatedCode: 'es2015'` for rollup build](https://github.com/vitejs/vite/pull/5018)
- Transpile to ES5 is now necessary even if the user code only includes ES5.
- [[#7877] fix: vite client types](https://github.com/vitejs/vite/pull/7877)
- `/// <reference lib="dom" />` is removed from `vite/client.d.ts`. `{ "lib": ["dom"] }` or `{ "lib": ["webworker"] }` is necessary in `tsconfig.json`.
- [[#8280] feat: non-blocking esbuild optimization at build time](https://github.com/vitejs/vite/pull/8280)
- `server.force` option was removed in favor of `force` option.

- `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
## Migration from v1

Since most of the logic should be done via plugin hooks instead of middlewares, the need for middlewares is greatly reduced. The internal server app is now a good old [connect](https://github.com/senchalabs/connect) instance instead of Koa.
Check the [Migration from v1 Guide](https://v2.vitejs.dev/guide/migration.html) in the Vite v2 docs first to see the needed changes to port your app to Vite v2, and then proceed with the changes on this page.
11 changes: 8 additions & 3 deletions docs/guide/static-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,17 @@ You can also deploy to a [custom domain](http://surge.sh/help/adding-a-custom-do
# creates a new app with a specified name
$ heroku apps:create example
```

6. Set buildpacks. We use `heroku/nodejs` to build the project and `heroku-buildpack-static` to serve it.

# set buildpack for static sites
$ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-static.git
```bash
# set buildpacks
$ heroku buildpacks:set heroku/nodejs
$ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-static.git
```

6. Deploy your site:
7. Deploy your site:

```bash
# publish site
Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ hero:
actions:
- theme: brand
text: Get Started
link: /guide/why
link: /guide/
- theme: alt
text: Why Vite?
link: /guide/
link: /guide/why
- theme: alt
text: View on GitHub
link: https://github.com/vitejs/vite
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
},
"devDependencies": {
"@babel/types": "^7.18.4",
"@microsoft/api-extractor": "^7.24.2",
"@rollup/plugin-typescript": "^8.3.2",
"@microsoft/api-extractor": "^7.25.0",
"@rollup/plugin-typescript": "^8.3.3",
"@types/babel__core": "^7.1.19",
"@types/babel__standalone": "^7.1.4",
"@types/convert-source-map": "^1.5.2",
Expand All @@ -57,26 +57,26 @@
"@types/semver": "^7.3.9",
"@types/stylus": "^0.48.38",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"@typescript-eslint/eslint-plugin": "^5.27.1",
"@typescript-eslint/parser": "^5.27.1",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"esbuild": "^0.14.38",
"eslint": "^8.16.0",
"eslint-define-config": "^1.5.0",
"eslint": "^8.17.0",
"eslint-define-config": "^1.5.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"esno": "^0.16.3",
"execa": "^5.1.1",
"fs-extra": "^10.1.0",
"kill-port": "^1.6.1",
"lint-staged": "^12.4.3",
"lint-staged": "^13.0.1",
"minimist": "^1.2.6",
"node-fetch": "^2.6.7",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"playwright-chromium": "^1.22.2",
"pnpm": "^7.1.7",
"pnpm": "^7.2.1",
"prettier": "2.6.2",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
Expand All @@ -89,8 +89,8 @@
"unbuild": "^0.7.4",
"vite": "workspace:*",
"vitepress": "1.0.0-draft.8",
"vitest": "^0.13.0",
"vue": "^3.2.36"
"vitest": "^0.14.2",
"vue": "^3.2.37"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --concurrent false",
Expand All @@ -110,7 +110,7 @@
"eslint --fix"
]
},
"packageManager": "pnpm@7.1.7",
"packageManager": "pnpm@7.2.1",
"pnpm": {
"overrides": {
"vite": "workspace:*",
Expand Down
2 changes: 2 additions & 0 deletions packages/create-vite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Currently supported template presets include:
- `svelte`
- `svelte-ts`

You can use `.` for the project name to scaffold in the current directory.

## Community Templates

create-vite is a tool to quickly start a project from a basic template for popular frameworks. Check out Awesome Vite for [community maintained templates](https://github.com/vitejs/awesome-vite#templates) that include other tools or target different frameworks. You can use a tool like [degit](https://github.com/Rich-Harris/degit) to scaffold your project with one of the templates.
Expand Down
Loading

0 comments on commit 1ed902b

Please sign in to comment.