Skip to content

Commit

Permalink
Merge branch 'main' into feat-async-plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jun 18, 2022
2 parents 59b57e9 + 11d2191 commit cddff8a
Show file tree
Hide file tree
Showing 94 changed files with 1,114 additions and 982 deletions.
2 changes: 0 additions & 2 deletions .github/renovate.json5
Expand Up @@ -19,8 +19,6 @@
"typescript",

// breaking changes
"react-router", // `react-router:v6.0.0+` has breaking changes
"react-router-dom", // `react-router-dom:v6.0.0+` has breaking changes
"source-map", // `source-map:v0.7.0+` needs more investigation
"dotenv-expand", // `dotenv-expand:6.0.0+` has breaking changes (#6858)
"kill-port", // `kill-port:^2.0.0 has perf issues (#8392)
Expand Down
27 changes: 20 additions & 7 deletions .github/workflows/ci.yml
Expand Up @@ -4,6 +4,8 @@ env:
# 7 GiB by default on GitHub, setting to 6 GiB
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
NODE_OPTIONS: --max-old-space-size=6144
# install playwright binary manually (because pnpm only runs install script once)
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"

on:
push:
Expand Down Expand Up @@ -38,10 +40,6 @@ jobs:
node_version: 16
fail-fast: false

env:
# Install playwright's binray under node_modules so it will be cached together
PLAYWRIGHT_BROWSERS_PATH: "0"

name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
steps:
- name: Checkout
Expand All @@ -59,8 +57,25 @@ jobs:
- name: Install deps
run: pnpm install

# Install playwright's binary under custom directory to cache
- name: Set Playwright path (non-windows)
if: runner.os != 'Windows'
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME/.cache/playwright-bin" >> $GITHUB_ENV
- name: Set Playwright path (windows)
if: runner.os == 'Windows'
run: echo "PLAYWRIGHT_BROWSERS_PATH=$HOME\.cache\playwright-bin" >> $env:GITHUB_ENV

- name: Cache Playwright's binary
uses: actions/cache@v3
with:
# Playwright removes unused browsers automatically
# So does not need to add playwright version to key
key: ${{ runner.os }}-playwright-bin-v1
path: ${{ env.PLAYWRIGHT_BROWSERS_PATH }}

- name: Install Playwright
run: pnpm playwright install
# does not need to explictly set chromium after https://github.com/microsoft/playwright/issues/14862 is solved
run: pnpm playwright install chromium

- name: Build
run: pnpm run build
Expand Down Expand Up @@ -97,8 +112,6 @@ jobs:

- name: Install deps
run: pnpm install
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"

- name: Build
run: pnpm run build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@ node_modules
playground-temp
temp
TODOs.md
.eslintcache
4 changes: 1 addition & 3 deletions docs/.vitepress/config.ts
Expand Up @@ -14,9 +14,7 @@ export default defineConfig({
logo: '/logo.svg',

editLink: {
repo: 'vitejs/vite',
branch: 'main',
dir: 'docs',
pattern: 'https://github.com/vitejs/vite/edit/main/docs/:path',
text: 'Suggest changes to this page'
},

Expand Down
6 changes: 6 additions & 0 deletions docs/config/dep-optimization-options.md
Expand Up @@ -45,3 +45,9 @@ Certain options are omitted since changing them would not be compatible with Vit

- `external` is also omitted, use Vite's `optimizeDeps.exclude` option
- `plugins` are merged with Vite's dep plugin

## optimizeDeps.force

- **Type:** `boolean`

Set to `true` to force dependency pre-bundling, ignoring previously cached optimized dependencies.
8 changes: 2 additions & 6 deletions docs/config/index.md
Expand Up @@ -41,14 +41,10 @@ const func = () => {
Since Vite ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints:

```js
/**
* @type {import('vite').UserConfig}
*/
const config = {
/** @type {import('vite').UserConfig} */
export default {
// ...
}

export default config
```

Alternatively, you can use the `defineConfig` helper which should provide intellisense without the need for jsdoc annotations:
Expand Down
9 changes: 1 addition & 8 deletions docs/config/server-options.md
Expand Up @@ -3,7 +3,7 @@
## server.host

- **Type:** `string | boolean`
- **Default:** `'127.0.0.1'`
- **Default:** `'localhost'`

Specify which IP addresses the server should listen on.
Set this to `0.0.0.0` or `true` to listen on all addresses, including LAN and public addresses.
Expand Down Expand Up @@ -107,13 +107,6 @@ Configure CORS for the dev server. This is enabled by default and allows any ori

Specify server response headers.

## server.force

- **Type:** `boolean`
- **Related:** [Dependency Pre-Bundling](/guide/dep-pre-bundling)

Set to `true` to force dependency pre-bundling.

## server.hmr

- **Type:** `boolean | { protocol?: string, host?: string, port?: number, path?: string, timeout?: number, overlay?: boolean, clientPort?: number, server?: Server }`
Expand Down
2 changes: 1 addition & 1 deletion docs/config/worker-options.md
Expand Up @@ -11,7 +11,7 @@ Output format for worker bundle.

- **Type:** [`(Plugin | Plugin[])[]`](./shared-options#plugins)

Vite plugins that apply to worker bundle
Vite plugins that apply to worker bundle. Note that [config.plugins](./shared-options#plugins) does not apply to workers, it should be configured here instead.

## worker.rollupOptions

Expand Down
6 changes: 6 additions & 0 deletions docs/guide/features.md
Expand Up @@ -511,6 +511,12 @@ By default, the worker script will be emitted as a separate chunk in the product
import MyWorker from './worker?worker&inline'
```

If you wish to retrieve the worker as a URL, add the `url` query:

```js
import MyWorker from './worker?worker&url'
```

See [Worker Options](/config/#worker-options) for details on configuring the bundling of all workers.

## Build Optimizations
Expand Down
39 changes: 32 additions & 7 deletions docs/guide/migration.md
Expand Up @@ -27,29 +27,48 @@ A small fraction of users will now require using [@vitejs/plugin-legacy](https:/
- `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))

## Dev Server Changes
## Achitecture changes and legacy Options

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.

:::warning
These options are marked as experimental and deprecated. They may be removed in a future v3 minor without respecting semver. Please pin the Vite version when using them.

- `legacy.devDepsScanner`
- `legacy.buildRollupPluginCommonjs`
- `legacy.buildSsrCjsExternalHeuristics`

:::

### Dev Server Changes

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.

Vite's default dev server host is now `localhost`. You can use [`server.host`](../config/server-options.md#server-host) to set it to `127.0.0.1`.

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.

To get back the v2 strategy, you can use [`optimizeDeps.devScan`](../config/dep-optimization-options.md#optimizedepsdevscan).
To get back the v2 strategy, you can use `legacy.devDepsScanner`.

## Build Changes
### Build Changes

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.

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

## SSR Changes
### SSR Changes

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.

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.
If using ESM for SSR isn't possible in your project, you can set `legacy.buildSsrCjsExternalHeuristics` to generate a CJS bundle using the same externalization strategy of Vite v2.

## General Changes

- 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.
- Terser is now an optional dependency. If you are using `build.minify: 'terser'`, you need to install it.
```shell
npm add -D terser
```

### `import.meta.glob`

Expand Down Expand Up @@ -93,6 +112,8 @@ There are some changes which only affects plugin/tool creators.
- `printHttpServerUrls` is removed
- `server.app`, `server.transformWithEsbuild` are removed
- `import.meta.hot.acceptDeps` is removed
- [[#6901] fix: sequential injection of tags in transformIndexHtml](https://github.com/vitejs/vite/pull/6901)
- `transformIndexHtml` now gets the correct content modified by earlier plugins, so the order of the injected tags now works as expected.
- [[#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)
Expand All @@ -105,8 +126,12 @@ Also there are other breaking changes which only affect few users.
- 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`.
- [[#8090] feat: preserve process env vars in lib build](https://github.com/vitejs/vite/pull/8090)
- `process.env.*` is now preserved in library mode
- [[#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.
- `server.force` option was removed in favor of `optimizeDeps.force` option.
- [[#8550] fix: dont handle sigterm in middleware mode](https://github.com/vitejs/vite/pull/8550)
- When running in middleware mode, Vite no longer kills process on `SIGTERM`.

## Migration from v1

Expand Down
16 changes: 8 additions & 8 deletions package.json
Expand Up @@ -14,8 +14,8 @@
],
"scripts": {
"preinstall": "npx only-allow pnpm",
"format": "prettier --write .",
"lint": "eslint packages/*/{src,types,__tests__}/** playground/**/__tests__/**/*.ts scripts/**",
"format": "prettier --write --cache .",
"lint": "eslint --cache packages/*/{src,types,__tests__}/** playground/**/__tests__/**/*.ts scripts/**",
"typecheck": "tsc -p scripts --noEmit && tsc -p playground --noEmit",
"test": "run-s test-unit test-serve test-build",
"test-serve": "vitest run -c vitest.config.e2e.ts",
Expand Down Expand Up @@ -77,7 +77,7 @@
"picocolors": "^1.0.0",
"playwright-chromium": "^1.22.2",
"pnpm": "^7.2.1",
"prettier": "2.6.2",
"prettier": "2.7.0",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
"rollup": "^2.75.6",
Expand All @@ -88,7 +88,7 @@
"typescript": "^4.6.4",
"unbuild": "^0.7.4",
"vite": "workspace:*",
"vitepress": "1.0.0-draft.8",
"vitepress": "^1.0.0-alpha.2",
"vitest": "^0.14.2",
"vue": "^3.2.37"
},
Expand All @@ -98,16 +98,16 @@
},
"lint-staged": {
"*": [
"prettier --write --ignore-unknown"
"prettier --write --cache --ignore-unknown"
],
"packages/*/{src,types}/**/*.ts": [
"eslint --fix"
"eslint --cache --fix"
],
"packages/**/*.d.ts": [
"eslint --fix"
"eslint --cache --fix"
],
"playground/**/__tests__/**/*.ts": [
"eslint --fix"
"eslint --cache --fix"
]
},
"packageManager": "pnpm@7.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-preact-ts/src/main.tsx
Expand Up @@ -2,4 +2,4 @@ import { render } from 'preact'
import { App } from './app'
import './index.css'

render(<App />, document.getElementById('app')!)
render(<App />, document.getElementById('app') as HTMLElement)
10 changes: 5 additions & 5 deletions packages/plugin-legacy/src/index.ts
Expand Up @@ -134,7 +134,7 @@ function viteLegacyPlugin(options: Options = {}): Plugin[] {
config.build,
'es',
opts,
options.externalSystemJS
true
)
return
}
Expand Down Expand Up @@ -566,7 +566,7 @@ async function buildPolyfillChunk(
buildOptions: BuildOptions,
format: 'iife' | 'es',
rollupOutputOptions: NormalizedOutputOptions,
externalSystemJS?: boolean
excludeSystemJS?: boolean
) {
let { minify, assetsDir } = buildOptions
minify = minify ? 'terser' : false
Expand All @@ -575,7 +575,7 @@ async function buildPolyfillChunk(
root: path.dirname(fileURLToPath(import.meta.url)),
configFile: false,
logLevel: 'error',
plugins: [polyfillsPlugin(imports, externalSystemJS)],
plugins: [polyfillsPlugin(imports, excludeSystemJS)],
build: {
write: false,
target: false,
Expand Down Expand Up @@ -614,7 +614,7 @@ const polyfillId = '\0vite/legacy-polyfills'

function polyfillsPlugin(
imports: Set<string>,
externalSystemJS?: boolean
excludeSystemJS?: boolean
): Plugin {
return {
name: 'vite:legacy-polyfills',
Expand All @@ -627,7 +627,7 @@ function polyfillsPlugin(
if (id === polyfillId) {
return (
[...imports].map((i) => `import "${i}";`).join('') +
(externalSystemJS ? '' : `import "systemjs/dist/s.min.js";`)
(excludeSystemJS ? '' : `import "systemjs/dist/s.min.js";`)
)
}
}
Expand Down

0 comments on commit cddff8a

Please sign in to comment.