Skip to content

Commit

Permalink
chore: merge upsteam main
Browse files Browse the repository at this point in the history
  • Loading branch information
dickeylth committed Mar 28, 2022
2 parents 70e6ca9 + 42c15f6 commit f12fd5e
Show file tree
Hide file tree
Showing 160 changed files with 4,448 additions and 1,883 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Expand Up @@ -11,6 +11,8 @@ on:
- main
- release/*
- feat/*
- fix/*
- perf/*
pull_request:
workflow_dispatch:

Expand All @@ -36,7 +38,7 @@ jobs:
name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
Expand Down Expand Up @@ -72,7 +74,7 @@ jobs:
runs-on: ubuntu-latest
name: "Lint: node-16, ubuntu-latest"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lock-closed-issues.yml
Expand Up @@ -11,11 +11,11 @@ jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v2
- uses: dessant/lock-threads@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
issue-lock-inactive-days: "14"
#issue-lock-comment: |
issue-inactive-days: "14"
#issue-comment: |
# This issue has been locked since it has been closed for more than 14 days.
#
# If you have found a concrete bug or regression related to it, please open a new [bug report](https://github.com/vitejs/vite/issues/new/choose) with a reproduction against the latest Vite version. If you have any other comments you should join the chat at [Vite Land](https://chat.vitejs.dev) or create a new [discussion](https://github.com/vitejs/vite/discussions).
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Expand Up @@ -15,7 +15,7 @@ jobs:
environment: Release
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-tag.yml
Expand Up @@ -13,7 +13,7 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Get pkgName for tag
id: tag
Expand Down
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -10,7 +10,9 @@ To develop and test the core `vite` package:

1. Run `pnpm i` in Vite's root folder

2. Go to `packages/vite` and run `pnpm run dev`. This starts `rollup` in watch mode.
2. Run `pnpm run build` in Vite's root folder.

3. If you are developing Vite itself, you can go to `packages/vite` and run `pnpm run dev` to automatically rebuild Vite whenever you change its code.

You can alternatively use [Vite.js Docker Dev](https://github.com/nystudio107/vitejs-docker-dev) for a containerized Docker setup for Vite.js development.

Expand Down Expand Up @@ -67,6 +69,8 @@ And re-run `pnpm install` to link the package.

Each package under `packages/playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files.

Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390).

Each test can be run under either dev server mode or build mode.

- `pnpm test` by default runs every test in both serve and build mode.
Expand Down
23 changes: 17 additions & 6 deletions docs/config/index.md
Expand Up @@ -27,14 +27,17 @@ You can also explicitly specify a config file to use with the `--config` CLI opt
vite --config my-config.js
```

Note that Vite will replace `__filename`, `__dirname`, and `import.meta.url`. Using these as variable names will result in an error:
::: tip NOTE
Vite will replace `__filename`, `__dirname`, and `import.meta.url` in **CommonJS** and **TypeScript** config files. Using these as variable names will result in an error:

```js
const __filename = "value"
// will be transformed to
const "path/vite.config.js" = "value"
```

:::

### Config Intellisense

Since Vite ships with TypeScript typings, you can leverage your IDE's intellisense with jsdoc type hints:
Expand Down Expand Up @@ -324,6 +327,14 @@ export default defineConfig(({ command, mode }) => {
})
```

### css.devSourcemap

- **Experimental**
- **Type:** `boolean`
- **Default:** `false`

Whether to enable sourcemaps during dev.

### json.namedExports

- **Type:** `boolean`
Expand Down Expand Up @@ -355,7 +366,7 @@ export default defineConfig(({ command, mode }) => {
})
```

By default, ESBuild is applied to `ts`, `jsx` and `tsx` files. You can customize this with `esbuild.include` and `esbuild.exclude`, both of which expect type of `string | RegExp | (string | RegExp)[]`.
By default, ESBuild is applied to `ts`, `jsx` and `tsx` files. You can customize this with `esbuild.include` and `esbuild.exclude`, which can be a regex, a [picomatch](https://github.com/micromatch/picomatch#globbing-features) pattern, or an array of either.

In addition, you can also use `esbuild.jsxInject` to automatically inject JSX helper imports for every file transformed by ESBuild:

Expand All @@ -374,7 +385,7 @@ export default defineConfig(({ command, mode }) => {
- **Type:** `string | RegExp | (string | RegExp)[]`
- **Related:** [Static Asset Handling](/guide/assets)

Specify additional [picomatch patterns](https://github.com/micromatch/picomatch) to be treated as static assets so that:
Specify additional [picomatch patterns](https://github.com/micromatch/picomatch#globbing-features) to be treated as static assets so that:

- They will be excluded from the plugin transform pipeline when referenced from HTML or directly requested over `fetch` or XHR.

Expand Down Expand Up @@ -549,7 +560,7 @@ export default defineConfig(({ command, mode }) => {

`clientPort` is an advanced option that overrides the port only on the client side, allowing you to serve the websocket on a different port than the client code looks for it on. Useful if you're using an SSL proxy in front of your dev server.

When using `server.middlewareMode` or `server.https`, assigning `server.hmr.server` to your HTTP(S) server will process HMR connection requests through your server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.
If specifying `server.hmr.server`, Vite will process HMR connection requests through the provided server. If not in middleware mode, Vite will attempt to process HMR connection requests through the existing server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port.

### server.watch

Expand Down Expand Up @@ -962,9 +973,9 @@ export default defineConfig({

- **Type:** `string | string[]`

By default, Vite will crawl your `index.html` to detect dependencies that need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead.
By default, Vite will crawl all your `.html` files to detect dependencies that need to be pre-bundled (ignoring `node_modules`, `build.outDir`, `__tests__` and `coverage`). If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead.

If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from Vite project root. This will overwrite default entries inference.
If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitily defined. If other folders needs to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`.

### optimizeDeps.exclude

Expand Down
8 changes: 8 additions & 0 deletions docs/guide/api-hmr.md
Expand Up @@ -123,3 +123,11 @@ The following HMR events are dispatched by Vite automatically:
- `'vite:error'` when an error occurs (e.g. syntax error)
Custom HMR events can also be sent from plugins. See [handleHotUpdate](./api-plugin#handlehotupdate) for more details.
## `hot.send(event, data)`
Send custom events back to Vite's dev server.
If called before connected, the data will be buffered and sent once the connection is established.
See [Client-server Communication](/guide/api-plugin.html#client-server-communication) for more details.
86 changes: 85 additions & 1 deletion docs/guide/api-plugin.md
Expand Up @@ -480,7 +480,7 @@ export default defineConfig({
Check out [Vite Rollup Plugins](https://vite-rollup-plugins.patak.dev) for a list of compatible official Rollup plugins with usage instructions.
## Path normalization
## Path Normalization
Vite normalizes paths while resolving ids to use POSIX separators ( / ) while preserving the volume in Windows. On the other hand, Rollup keeps resolved paths untouched by default, so resolved ids have win32 separators ( \\ ) in Windows. However, Rollup plugins use a [`normalizePath` utility function](https://github.com/rollup/plugins/tree/master/packages/pluginutils#normalizepath) from `@rollup/pluginutils` internally, which converts separators to POSIX before performing comparisons. This means that when these plugins are used in Vite, the `include` and `exclude` config pattern and other similar paths against resolved ids comparisons work correctly.
Expand All @@ -492,3 +492,87 @@ import { normalizePath } from 'vite'
normalizePath('foo\\bar') // 'foo/bar'
normalizePath('foo/bar') // 'foo/bar'
```
## Client-server Communication
Since Vite 2.9, we provide some utilities for plugins to help handle the communication with clients.
### Server to Client
On the plugin side, we could use `server.ws.send` to boardcast events to all the clients:
```js
// vite.config.js
export default defineConfig({
plugins: [
{
// ...
configureServer(server) {
server.ws.send('my:greetings', { msg: 'hello' })
}
}
]
})
```
::: tip NOTE
We recommend **alway prefixing** your event names to avoid collisions with other plugins.
:::
On the client side, use [`hot.on`](/guide/api-hmr.html#hot-on-event-cb) to listen to the events:
```ts
// client side
if (import.meta.hot) {
import.meta.hot.on('my:greetings', (data) => {
console.log(data.msg) // hello
})
}
```
### Client to Server
To send events from the client to the server, we can use [`hot.send`](/guide/api-hmr.html#hot-send-event-payload):
```ts
// client side
if (import.meta.hot) {
import.meta.hot.send('my:from-client', { msg: 'Hey!' })
}
```
Then use `server.ws.on` and listen to the events on the server side:
```js
// vite.config.js
export default defineConfig({
plugins: [
{
// ...
configureServer(server) {
server.ws.on('my:from-client', (data, client) => {
console.log('Message from client:', data.msg) // Hey!
// reply only to the client (if needed)
client.send('my:ack', { msg: 'Hi! I got your message!' })
})
}
}
]
})
```
### TypeScript for Custom Events
It is possible to type custom events by extending the `CustomEventMap` interface:
```ts
// events.d.ts
import 'vite/types/customEvent'

declare module 'vite/types/customEvent' {
interface CustomEventMap {
'custom:foo': { msg: string }
// 'event-key': payload
}
}
```
20 changes: 20 additions & 0 deletions docs/guide/features.md
Expand Up @@ -352,6 +352,24 @@ In the production build, `.wasm` files smaller than `assetInlineLimit` will be i

## Web Workers

### Import with Constructors

A web worker script can be imported using [`new Worker()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/Worker) and [`new SharedWorker()`](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/SharedWorker). Compared to the worker suffixes, this syntax leans closer to the standards and is the **recommended** way to create workers.

```ts
const worker = new Worker(new URL('./worker.js', import.meta.url))
```

The worker constructor also accepts options, which can be used to create "module" workers:

```ts
const worker = new Worker(new URL('./worker.js', import.meta.url), {
type: 'module'
})
```

### Import with Query Suffixes

A web worker script can be directly imported by appending `?worker` or `?sharedworker` to the import request. The default export will be a custom worker constructor:

```js
Expand All @@ -368,6 +386,8 @@ By default, the worker script will be emitted as a separate chunk in the product
import MyWorker from './worker?worker&inline'
```

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

## Build Optimizations

> Features listed below are automatically applied as part of the build process and there is no need for explicit configuration unless you want to disable them.
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Expand Up @@ -6,7 +6,7 @@ const config: Config.InitialOptions = {
testMatch: process.env.VITE_TEST_BUILD
? ['**/playground/**/*.spec.[jt]s?(x)']
: ['**/*.spec.[jt]s?(x)'],
testTimeout: process.env.CI ? 30000 : 10000,
testTimeout: process.env.CI ? 50000 : 20000,
globalSetup: './scripts/jestGlobalSetup.cjs',
globalTeardown: './scripts/jestGlobalTeardown.cjs',
testEnvironment: './scripts/jestEnv.cjs',
Expand Down
32 changes: 16 additions & 16 deletions package.json
Expand Up @@ -34,41 +34,41 @@
"ci-docs": "run-s build-vite build-plugin-vue build-docs"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.19.4",
"@microsoft/api-extractor": "^7.19.5",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.22",
"@types/jest": "^27.4.1",
"@types/node": "^16.11.26",
"@types/prompts": "^2.0.14",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"esbuild": "^0.14.14",
"eslint": "^8.8.0",
"eslint-define-config": "^1.2.4",
"esbuild": "^0.14.27",
"eslint": "^8.12.0",
"eslint-define-config": "^1.3.0",
"eslint-plugin-node": "^11.1.0",
"execa": "^5.1.1",
"fs-extra": "^10.0.0",
"fs-extra": "^10.0.1",
"jest": "^27.5.1",
"lint-staged": "^12.3.3",
"minimist": "^1.2.5",
"lint-staged": "^12.3.7",
"minimist": "^1.2.6",
"node-fetch": "^2.6.6",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"playwright-chromium": "^1.18.1",
"prettier": "2.5.1",
"playwright-chromium": "^1.20.1",
"prettier": "2.6.1",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
"rollup": "^2.59.0",
"semver": "^7.3.5",
"simple-git-hooks": "^2.7.0",
"sirv": "^2.0.2",
"ts-jest": "^27.1.3",
"ts-jest": "^27.1.4",
"ts-node": "^10.4.0",
"typescript": "~4.5.4",
"vite": "workspace:*",
"vitepress": "^0.21.6"
"vitepress": "^0.22.3"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --concurrent false",
Expand All @@ -85,7 +85,7 @@
"eslint --ext .ts"
]
},
"packageManager": "pnpm@6.30.0",
"packageManager": "pnpm@6.32.3",
"pnpm": {
"overrides": {
"vite": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/package.json
Expand Up @@ -26,7 +26,7 @@
"homepage": "https://github.com/vitejs/vite/tree/main/packages/create-vite#readme",
"dependencies": {
"kolorist": "^1.5.1",
"minimist": "^1.2.5",
"minimist": "^1.2.6",
"prompts": "^2.4.2"
}
}
10 changes: 10 additions & 0 deletions packages/playground/assets/__tests__/assets.spec.ts
Expand Up @@ -194,6 +194,16 @@ test('?url import', async () => {
)
})

test('?url import on css', async () => {
const src = readFile('css/icons.css')
const txt = await page.textContent('.url-css')
expect(txt).toEqual(
isBuild
? `data:text/css;base64,${Buffer.from(src).toString('base64')}`
: '/foo/css/icons.css'
)
})

describe('unicode url', () => {
test('from js import', async () => {
const src = readFile('テスト-測試-white space.js')
Expand Down

0 comments on commit f12fd5e

Please sign in to comment.