diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 3954ca49c11479..cde7dfb03825ed 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -11,6 +11,8 @@ on:
- main
- release/*
- feat/*
+ - fix/*
+ - perf/*
pull_request:
workflow_dispatch:
@@ -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
@@ -44,7 +46,7 @@ jobs:
version: 6
- name: Set node version to ${{ matrix.node_version }}
- uses: actions/setup-node@v2
+ uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
cache: "pnpm"
@@ -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
@@ -82,7 +84,7 @@ jobs:
version: 6
- name: Set node version to 16
- uses: actions/setup-node@v2
+ uses: actions/setup-node@v3
with:
node-version: 16
cache: "pnpm"
diff --git a/.github/workflows/lock-closed-issues.yml b/.github/workflows/lock-closed-issues.yml
index e20c3e3c8e8138..1f24f316952ea0 100644
--- a/.github/workflows/lock-closed-issues.yml
+++ b/.github/workflows/lock-closed-issues.yml
@@ -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).
diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index eb8f4513707872..c58c28adac7b40 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -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
@@ -23,7 +23,7 @@ jobs:
version: 6
- name: Set node version to 16.x
- uses: actions/setup-node@v2
+ uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: https://registry.npmjs.org/
diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml
index f9d5b8de30bec9..21af4792d4741a 100644
--- a/.github/workflows/release-tag.yml
+++ b/.github/workflows/release-tag.yml
@@ -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
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 00000000000000..4abbb42e5ef159
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1,7 @@
+hoist-pattern[]=*eslint*
+hoist-pattern[]=*babel*
+hoist-pattern[]=*jest*
+hoist-pattern[]=@emotion/*
+hoist-pattern[]=postcss
+hoist-pattern[]=pug
+hoist-pattern[]=source-map-support
diff --git a/.prettierignore b/.prettierignore
index 1692b9d26cfa20..c624a3a21eecfe 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -10,3 +10,4 @@ pnpm-lock.yaml
pnpm-workspace.yaml
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
packages/playground/html/invalid.html
+packages/playground/worker/classic-worker.js
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 5b8f1fed7192c3..b105499159bebb 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -10,10 +10,42 @@ 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.
+## Debugging
+
+If you want to use break point and explore code execution you can use the ["Run and debug"](https://code.visualstudio.com/docs/editor/debugging) feature from vscode.
+
+1. Add a `debugger` statement where you want to stop the code execution.
+
+2. Click on the "Run and Debug" icon in the activity bar of the editor.
+
+3. Click on the "JavaScript Debug Terminal" button.
+
+4. It will open a terminal, then go to `packages/playground/xxx` and run `pnpm run dev`.
+
+5. The execution will stop and you'll use the [Debug toolbar](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) to continue, step over, restart the process...
+
+### Debugging errors in Jest tests using Playwright (Chromium)
+
+Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Jest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup:
+
+1. Add a `debugger` statement to the `scripts/jestPerTestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits.
+
+1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve -- --runInBand resolve`.
+
+1. Wait for inspector devtools to open in your browser and the debugger to attach.
+
+1. In the sources panel in the right column, click the play button to resume execution and allow the tests to run which will open a Chromium instance.
+
+1. Focusing the Chomium instance, you can open the browser devtools and inspect the console there to find the underlying problems.
+
+1. To close everything, just stop the test process back in your terminal.
+
## Testing Vite against external packages
You may wish to test your locally-modified copy of Vite against another package that is built with Vite. For pnpm, after building Vite, you can use [`pnpm.overrides`](https://pnpm.io/package_json#pnpmoverrides). Please note that `pnpm.overrides` must be specified in the root `package.json` and you must first list the package as a dependency in the root `package.json`:
@@ -37,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.
@@ -195,7 +229,7 @@ The english docs are embedded in the main Vite repo, to allow contributors to wo
1. In order to get all doc files, you first need to clone this repo in your personal account.
2. Keep all the files in `docs/` and remove everything else.
- - You should setup your translation site based on all the files in `docs/` folder as a Vitepress project.
+ - You should setup your translation site based on all the files in `docs/` folder as a VitePress project.
(that said, `package.json` is need).
- Refresh git history by removing `.git` and then `git init`
@@ -204,7 +238,7 @@ The english docs are embedded in the main Vite repo, to allow contributors to wo
- During this stage, you may be translating documents and synchronizing updates at the same time, but don't worry about that, it's very common in translation contribution.
-4. Push your commits to your Github repo. you can setup a netlify preview as well.
-5. Use [Ryu-cho](https://github.com/vuejs-translations/ryu-cho) tool to setup a Github Action, automatically track English docs update later.
+4. Push your commits to your GitHub repo. you can setup a netlify preview as well.
+5. Use [Ryu-cho](https://github.com/vuejs-translations/ryu-cho) tool to setup a GitHub Action, automatically track English docs update later.
We recommend talking with others in Vite Land so you find more contributors for your language to share the maintenance work. Once the translation is done, communicate it to the Vite team so the repo can be moved to the official vitejs org in GitHub.
diff --git a/docs/blog/announcing-vite2.md b/docs/blog/announcing-vite2.md
index 0bf520dfdfcb9a..0007205debba4a 100644
--- a/docs/blog/announcing-vite2.md
+++ b/docs/blog/announcing-vite2.md
@@ -34,7 +34,7 @@ The [programmatic API](https://vitejs.dev/guide/api-javascript.html) has also be
### esbuild Powered Dep Pre-Bundling
-Since Vite is a native ESM dev server, it pre-bundles dependencies to reduce the number browser requests and handle CommonJS to ESM conversion. Previously Vite did this using Rollup, and in 2.0 it now uses `esbuild` which results in 10-100x faster dependency pre-bundling. As a reference, cold-booting a test app with heavy dependencies like React Material UI previously took 28 seconds on an M1-powered Macbook Pro and now takes ~1.5 seconds. Expect similar improvements if you are switching from a traditional bundler based setup.
+Since Vite is a native ESM dev server, it pre-bundles dependencies to reduce the number browser requests and handle CommonJS to ESM conversion. Previously Vite did this using Rollup, and in 2.0 it now uses `esbuild` which results in 10-100x faster dependency pre-bundling. As a reference, cold-booting a test app with heavy dependencies like React Material UI previously took 28 seconds on an M1-powered MacBook Pro and now takes ~1.5 seconds. Expect similar improvements if you are switching from a traditional bundler based setup.
### First-class CSS Support
diff --git a/docs/config/index.md b/docs/config/index.md
index 88c2ab62ac3b92..5b618364cf2b3a 100644
--- a/docs/config/index.md
+++ b/docs/config/index.md
@@ -27,7 +27,8 @@ 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"
@@ -35,6 +36,8 @@ const __filename = "value"
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:
@@ -96,6 +99,22 @@ export default defineConfig(async ({ command, mode }) => {
})
```
+### Environment Variables
+
+Vite doesn't load `.env` files by default as the files to load can only be determined after evaluating the Vite config, for example, the `root` and `envDir` options affects the loading behaviour. However, you can use the exported `loadEnv` helper to load the specific `.env` file if needed.
+
+```js
+import { defineConfig, loadEnv } from 'vite'
+
+export default defineConfig(({ command, mode }) => {
+ // Load env file based on `mode` in the current working directory
+ const env = loadEnv(mode, process.cwd())
+ return {
+ // build specific config
+ }
+})
+```
+
## Shared Options
### root
@@ -137,11 +156,15 @@ export default defineConfig(async ({ command, mode }) => {
- Starting from `2.0.0-beta.70`, string values will be used as raw expressions, so if defining a string constant, it needs to be explicitly quoted (e.g. with `JSON.stringify`).
+ - To be consistent with [esbuild behavior](https://esbuild.github.io/api/#define), expressions must either be a JSON object (null, boolean, number, string, array, or object) or a single identifier.
+
- Replacements are performed only when the match is surrounded by word boundaries (`\b`).
+ ::: warning
Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only.
For example, `process.env.FOO` and `__APP_VERSION__` are good fits. But `process` or `global` should not be put into this option. Variables can be shimmed or polyfilled instead.
+ :::
::: tip NOTE
For TypeScript users, make sure to add the type declarations in the `env.d.ts` or `vite-env.d.ts` file to get type checks and Intellisense.
@@ -223,6 +246,10 @@ export default defineConfig(async ({ command, mode }) => {
Vite has a list of "allowed conditions" and will match the first condition that is in the allowed list. The default allowed conditions are: `import`, `module`, `browser`, `default`, and `production/development` based on current mode. The `resolve.conditions` config option allows specifying additional allowed conditions.
+ :::warning Resolving subpath exports
+ Export keys ending with "/" is deprecated by Node and may not work well. Please contact the package author to use [`*` subpath patterns](https://nodejs.org/api/packages.html#package-entry-points) instead.
+ :::
+
### resolve.mainFields
- **Type:** `string[]`
@@ -277,7 +304,7 @@ export default defineConfig(async ({ command, mode }) => {
- **Type:** `string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] })`
- Inline PostCSS config (expects the same format as `postcss.config.js`), or a custom path to search PostCSS config from (default is project root). The search is done using [postcss-load-config](https://github.com/postcss/postcss-load-config).
+ Inline PostCSS config (expects the same format as `postcss.config.js`), or a custom directory to search PostCSS config from (default is project root). The search is done using [postcss-load-config](https://github.com/postcss/postcss-load-config) and only the supported config file names are loaded.
Note if an inline config is provided, Vite will not search for other PostCSS config sources.
@@ -285,7 +312,7 @@ export default defineConfig(async ({ command, mode }) => {
- **Type:** `Record`
- Specify options to pass to CSS pre-processors. Example:
+ Specify options to pass to CSS pre-processors. The file extensions are used as keys for the options. Example:
```js
export default defineConfig({
@@ -293,12 +320,23 @@ export default defineConfig(async ({ command, mode }) => {
preprocessorOptions: {
scss: {
additionalData: `$injectedColor: orange;`
+ },
+ styl: {
+ additionalData: `$injectedColor ?= orange`
}
}
}
})
```
+### css.devSourcemap
+
+- **Experimental**
+- **Type:** `boolean`
+- **Default:** `false`
+
+ Whether to enable sourcemaps during dev.
+
### json.namedExports
- **Type:** `boolean`
@@ -319,7 +357,7 @@ export default defineConfig(async ({ command, mode }) => {
- **Type:** `ESBuildOptions | false`
- `ESBuildOptions` extends [ESbuild's own transform options](https://esbuild.github.io/api/#transform-api). The most common use case is customizing JSX:
+ `ESBuildOptions` extends [esbuild's own transform options](https://esbuild.github.io/api/#transform-api). The most common use case is customizing JSX:
```js
export default defineConfig({
@@ -330,9 +368,9 @@ export default defineConfig(async ({ 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:
+ In addition, you can also use `esbuild.jsxInject` to automatically inject JSX helper imports for every file transformed by esbuild:
```js
export default defineConfig({
@@ -342,14 +380,14 @@ export default defineConfig(async ({ command, mode }) => {
})
```
- Set to `false` to disable ESbuild transforms.
+ Set to `false` to disable esbuild transforms.
### assetsInclude
- **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.
@@ -499,6 +537,12 @@ export default defineConfig(async ({ command, mode }) => {
Configure CORS for the dev server. This is enabled by default and allows any origin. Pass an [options object](https://github.com/expressjs/cors) to fine tune the behavior or `false` to disable.
+### server.headers
+
+- **Type:** `OutgoingHttpHeaders`
+
+ Specify server response headers.
+
### server.force
- **Type:** `boolean`
@@ -516,7 +560,7 @@ export default defineConfig(async ({ 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
@@ -580,6 +624,12 @@ async function createServer() {
createServer()
```
+### server.base
+
+- **Type:** `string | undefined`
+
+ Prepend this folder to http requests, for use when proxying vite as a subfolder. Should start and end with the `/` character.
+
### server.fs.strict
- **Type:** `boolean`
@@ -799,7 +849,7 @@ export default defineConfig({
- **Type:** `boolean | 'terser' | 'esbuild'`
- **Default:** `'esbuild'`
- Set to `false` to disable minification, or specify the minifier to use. The default is [Esbuild](https://github.com/evanw/esbuild) which is 20 ~ 40x faster than terser and only 1 ~ 2% worse compression. [Benchmarks](https://github.com/privatenumber/minification-benchmarks)
+ Set to `false` to disable minification, or specify the minifier to use. The default is [esbuild](https://github.com/evanw/esbuild) which is 20 ~ 40x faster than terser and only 1 ~ 2% worse compression. [Benchmarks](https://github.com/privatenumber/minification-benchmarks)
Note the `build.minify` option is not available when using the `'es'` format in lib mode.
@@ -923,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
diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md
index f4ddf59d8abcd1..46eabab04e8868 100644
--- a/docs/guide/api-hmr.md
+++ b/docs/guide/api-hmr.md
@@ -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.
diff --git a/docs/guide/api-javascript.md b/docs/guide/api-javascript.md
index 1651923c06cdcb..0128be26bd92ba 100644
--- a/docs/guide/api-javascript.md
+++ b/docs/guide/api-javascript.md
@@ -1,6 +1,6 @@
# JavaScript API
-Vite's JavaScript APIs are fully typed, and it's recommended to use TypeScript or enable JS type checking in VSCode to leverage the intellisense and validation.
+Vite's JavaScript APIs are fully typed, and it's recommended to use TypeScript or enable JS type checking in VS Code to leverage the intellisense and validation.
## `createServer`
@@ -94,7 +94,7 @@ interface ViteDevServer {
*/
ssrLoadModule(
url: string,
- options?: { isolated?: boolean }
+ options?: { fixStacktrace?: boolean }
): Promise>
/**
* Fix ssr error stacktrace.
diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md
index 01b42980197473..4a5b1c07c7893e 100644
--- a/docs/guide/api-plugin.md
+++ b/docs/guide/api-plugin.md
@@ -458,7 +458,7 @@ In general, as long as a Rollup plugin fits the following criteria then it shoul
- It doesn't use the [`moduleParsed`](https://rollupjs.org/guide/en/#moduleparsed) hook.
- It doesn't have strong coupling between bundle-phase hooks and output-phase hooks.
-If a Rollup plugin only makes sense for the build phase, then it can be specified under `build.rollupOptions.plugins` instead.
+If a Rollup plugin only makes sense for the build phase, then it can be specified under `build.rollupOptions.plugins` instead. It will work the same as a Vite plugin with `enforce: 'post'` and `apply: 'build'`.
You can also augment an existing Rollup plugin with Vite-only properties:
@@ -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.
@@ -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 broadcast 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
+ }
+}
+```
diff --git a/docs/guide/assets.md b/docs/guide/assets.md
index fd5aa46f49467f..53ac153f9465bd 100644
--- a/docs/guide/assets.md
+++ b/docs/guide/assets.md
@@ -103,8 +103,13 @@ function getImageUrl(name) {
}
```
-During the production build, Vite will perform necessary transforms so that the URLs still point to the correct location even after bundling and asset hashing.
+During the production build, Vite will perform necessary transforms so that the URLs still point to the correct location even after bundling and asset hashing. However, the URL string must be static so it can be analyzed, otherwise the code will be left as is, which can cause runtime errors if `build.target` does not support `import.meta.url`
-::: warning Note: Does not work with SSR
+```js
+// Vite will not transform this
+const imgUrl = new URL(imagePath, import.meta.url).href
+```
+
+::: warning Does not work with SSR
This pattern does not work if you are using Vite for Server-Side Rendering, because `import.meta.url` have different semantics in browsers vs. Node.js. The server bundle also cannot determine the client host URL ahead of time.
:::
diff --git a/docs/guide/backend-integration.md b/docs/guide/backend-integration.md
index a30831e735fff7..55a4b87f1ac481 100644
--- a/docs/guide/backend-integration.md
+++ b/docs/guide/backend-integration.md
@@ -33,7 +33,6 @@ If you need a custom integration, you can follow the steps in this guide to conf
```html
-
```
diff --git a/docs/guide/build.md b/docs/guide/build.md
index 1dff97bf5fb243..822374e8d0ab2c 100644
--- a/docs/guide/build.md
+++ b/docs/guide/build.md
@@ -43,6 +43,20 @@ module.exports = defineConfig({
For example, you can specify multiple Rollup outputs with plugins that are only applied during build.
+## Chunking Strategy
+
+You can configure how chunks are split using `build.rollupOptions.output.manualChunks` (see [Rollup docs](https://rollupjs.org/guide/en/#outputmanualchunks)). Until Vite 2.8, the default chunking strategy divided the chunks into `index` and `vendor`. It is a good strategy for some SPAs, but it is hard to provide a general solution for every Vite target use case. From Vite 2.9, `manualChunks` is no longer modified by default. You can continue to use the Split Vendor Chunk strategy by adding the `splitVendorChunkPlugin` in your config file:
+
+```js
+// vite.config.js
+import { splitVendorChunkPlugin } from 'vite'
+module.exports = defineConfig({
+ plugins: [splitVendorChunkPlugin()]
+})
+```
+
+This strategy is also provided as a `splitVendorChunk({ cache: SplitVendorChunkCache })` factory, in case composition with custom logic is needed. `cache.reset()` needs to be called at `buildStart` for build watch mode to work correctly in this case.
+
## Rebuild on files changes
You can enable rollup watcher with `vite build --watch`. Or, you can directly adjust the underlying [`WatcherOptions`](https://rollupjs.org/guide/en/#watch-options) via `build.watch`:
@@ -58,6 +72,8 @@ module.exports = defineConfig({
})
```
+With the `--watch` flag enabled, changes to the `vite.config.js`, as well as any files to be bundled, will trigger a rebuild.
+
## Multi-Page App
Suppose you have the following source code structure:
@@ -130,6 +146,15 @@ module.exports = defineConfig({
})
```
+The entry file would contain exports that can be imported by users of your package:
+
+```js
+// lib/main.js
+import Foo from './Foo.vue'
+import Bar from './Bar.vue'
+export { Foo, Bar }
+```
+
Running `vite build` with this config uses a Rollup preset that is oriented towards shipping libraries and produces two bundle formats: `es` and `umd` (configurable via `build.lib`):
```
diff --git a/docs/guide/dep-pre-bundling.md b/docs/guide/dep-pre-bundling.md
index 6864ef55899eba..0afce072e9fcc3 100644
--- a/docs/guide/dep-pre-bundling.md
+++ b/docs/guide/dep-pre-bundling.md
@@ -3,10 +3,10 @@
When you run `vite` for the first time, you may notice this message:
```
-Optimizable dependencies detected:
-react, react-dom
-Pre-bundling them to speed up dev server page load...
-(this will be run only when your dependencies have changed)
+Pre-bundling dependencies:
+ react
+ react-dom
+(this will be run only when your dependencies or config have changed)
```
## The Why
@@ -28,6 +28,10 @@ This is Vite performing what we call "dependency pre-bundling". This process ser
By pre-bundling `lodash-es` into a single module, we now only need one HTTP request instead!
+::: tip NOTE
+Dependency pre-bundling only applies in development mode, and uses `esbuild` to convert dependencies to ESM. In production builds, `@rollup/plugin-commonjs` is used instead.
+:::
+
## Automatic Dependency Discovery
If an existing cache is not found, Vite will crawl your source code and automatically discover dependency imports (i.e. "bare imports" that expect to be resolved from `node_modules`) and use these found imports as entry points for the pre-bundle. The pre-bundling is performed with `esbuild` so it's typically very fast.
@@ -36,11 +40,27 @@ After the server has already started, if a new dependency import is encountered
## Monorepos and Linked Dependencies
-In a monorepo setup, a dependency may be a linked package from the same repo. Vite automatically detects dependencies that are not resolved from `node_modules` and treats the linked dep as source code. It will not attempt to bundle the linked dep, and instead will analyze the linked dep's dependency list instead.
+In a monorepo setup, a dependency may be a linked package from the same repo. Vite automatically detects dependencies that are not resolved from `node_modules` and treats the linked dep as source code. It will not attempt to bundle the linked dep, and will analyze the linked dep's dependency list instead.
+
+However, this requires the linked dep to be exported as ESM. If not, you can add the dependency to [`optimizeDeps.include`](/config/#optimizedeps-include) and [`build.commonjsOptions.include`](/config/#build-commonjsoptions) in your config.
+
+```js
+export default defineConfig({
+ optimizeDeps: {
+ include: ['linked-dep']
+ },
+ build: {
+ commonjsOptions: {
+ include: [/linked-dep/, /node_modules/]
+ }
+ }
+})
+```
+
+When making changes to the linked dep, restart the dev server with the `--force` command line option for the changes to take effect.
-::: warning Note
-Linked dependencies might not work properly in the final build due to differences in dependency resolution.
-Use `npm package` instead for all local dependencies to avoid issues in the final bundle.
+::: warning Deduping
+Due to differences in linked dependency resolution, transitive dependencies can deduplicated incorrectly, causing issues when used in runtime. If you stumble on this issue, use `npm pack` on the linked dependency to fix it.
:::
## Customizing the Behavior
@@ -57,7 +77,7 @@ Both `include` and `exclude` can be used to deal with this. If the dependency is
Vite caches the pre-bundled dependencies in `node_modules/.vite`. It determines whether it needs to re-run the pre-bundling step based on a few sources:
-- The `dependencies` list in your `package.json`
+- The `dependencies` list in your `package.json`.
- Package manager lockfiles, e.g. `package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml`.
- Relevant fields in your `vite.config.js`, if present.
diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md
index d3a6a575bce64c..1649feda8c7501 100644
--- a/docs/guide/env-and-mode.md
+++ b/docs/guide/env-and-mode.md
@@ -37,7 +37,7 @@ Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional enviro
An env file for a specific mode (e.g. `.env.production`) will take higher priority than a generic one (e.g. `.env`).
-In addition, environment variables that already exist when Vite is executed have the highest priority and will not be overwritten by `.env` files.
+In addition, environment variables that already exist when Vite is executed have the highest priority and will not be overwritten by `.env` files. For example, when running `VITE_SOME_KEY=123 vite build`.
`.env` files are loaded at the start of Vite. Restart the server after making changes.
:::
@@ -57,7 +57,7 @@ If you want to customize env variables prefix, see [envPrefix](/config/index#env
:::warning SECURITY NOTES
-- `.env.*.local` files are local-only and can contain sensitive variables. You should add `.local` to your `.gitignore` to avoid them being checked into git.
+- `.env.*.local` files are local-only and can contain sensitive variables. You should add `*.local` to your `.gitignore` to avoid them being checked into git.
- Since any variables exposed to your Vite source code will end up in your client bundle, `VITE_*` variables should _not_ contain any sensitive information.
:::
diff --git a/docs/guide/features.md b/docs/guide/features.md
index c7fd2424b53cb1..ebed85cd2d529d 100644
--- a/docs/guide/features.md
+++ b/docs/guide/features.md
@@ -298,10 +298,10 @@ const modules = {
}
```
-`import.meta.glob` and `import.meta.globEager` also support importing files as strings, similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string). Here, we use the [Import Assertions](https://github.com/tc39/proposal-import-assertions#synopsis) syntax to import.
+`import.meta.glob` and `import.meta.globEager` also support importing files as strings (similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string)) with the [Import Reflection](https://github.com/tc39/proposal-import-reflection) syntax:
```js
-const modules = import.meta.glob('./dir/*.js', { assert: { type: 'raw' } })
+const modules = import.meta.glob('./dir/*.js', { as: 'raw' })
```
The above will be transformed into the following:
@@ -317,7 +317,7 @@ const modules = {
Note that:
- This is a Vite-only feature and is not a web or ES standard.
-- The glob patterns are treated like import specifiers: they must be either relative (start with `./`) or absolute (start with `/`, resolved relative to project root).
+- The glob patterns are treated like import specifiers: they must be either relative (start with `./`) or absolute (start with `/`, resolved relative to project root) or an alias path (see [`resolve.alias` option](/config/#resolve-alias)).
- The glob matching is done via `fast-glob` - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax).
- You should also be aware that glob imports do not accept variables, you need to directly pass the string pattern.
- The glob patterns cannot contain the same quote string (i.e. `'`, `"`, `` ` ``) as outer quotes, e.g. `'/Tom\'s files/**'`, use `"/Tom's files/**"` instead.
@@ -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
@@ -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.
diff --git a/docs/guide/static-deploy.md b/docs/guide/static-deploy.md
index 43b047dd7f53eb..8c6c219f568a9e 100644
--- a/docs/guide/static-deploy.md
+++ b/docs/guide/static-deploy.md
@@ -299,7 +299,7 @@ Vercel CLI
### Vercel for Git
-1. Push your code to your git repository (GitHub, GitLab, BitBucket).
+1. Push your code to your git repository (GitHub, GitLab, Bitbucket).
2. [Import your Vite project](https://vercel.com/new) into Vercel.
3. Vercel will detect that you are using Vite and will enable the correct settings for your deployment.
4. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/))
diff --git a/docs/guide/why.md b/docs/guide/why.md
index 59e9c138eb7dca..9a24cf64777611 100644
--- a/docs/guide/why.md
+++ b/docs/guide/why.md
@@ -18,7 +18,7 @@ Vite improves the dev server start time by first dividing the modules in an appl
- **Dependencies** are mostly plain JavaScript that do not change often during development. Some large dependencies (e.g. component libraries with hundreds of modules) are also quite expensive to process. Dependencies may also be shipped in various module formats (e.g. ESM or CommonJS).
- Vite [pre-bundles dependencies](./dep-pre-bundling) using [esbuild](https://esbuild.github.io/). Esbuild is written in Go and pre-bundles dependencies 10-100x faster than JavaScript-based bundlers.
+ Vite [pre-bundles dependencies](./dep-pre-bundling) using [esbuild](https://esbuild.github.io/). esbuild is written in Go and pre-bundles dependencies 10-100x faster than JavaScript-based bundlers.
- **Source code** often contains non-plain JavaScript that needs transforming (e.g. JSX, CSS or Vue/Svelte components), and will be edited very often. Also, not all source code needs to be loaded at the same time (e.g. with route-based code-splitting).
@@ -32,7 +32,7 @@ Vite improves the dev server start time by first dividing the modules in an appl
When a file is edited in a bundler-based build setup, it is inefficient to rebuild the whole bundle for obvious reasons: the update speed will degrade linearly with the size of the app.
-Some bundler dev server runs the bundling in memory so that it only needs to invalidate part of its module graph when a file changes, but it still needs to re-construct the entire bundle and reload the web page. Reconstructing the bundle can be expensive, and reloading the page blows away the current state of the application. This is why some bundlers support Hot Module Replacement (HMR): allowing a module to "hot replace" itself without affecting the rest of the page. This greatly improves DX - however, in practice we've found that even HMR update speed deteriorates significantly as the size of the application grows.
+In some bundlers, the dev server runs the bundling in memory so that it only needs to invalidate part of its module graph when a file changes, but it still needs to re-construct the entire bundle and reload the web page. Reconstructing the bundle can be expensive, and reloading the page blows away the current state of the application. This is why some bundlers support Hot Module Replacement (HMR): allowing a module to "hot replace" itself without affecting the rest of the page. This greatly improves DX - however, in practice we've found that even HMR update speed deteriorates significantly as the size of the application grows.
In Vite, HMR is performed over native ESM. When a file is edited, Vite only needs to precisely invalidate the chain between the edited module and its closest HMR boundary (most of the time only the module itself), making HMR updates consistently fast regardless of the size of your application.
diff --git a/jest.config.ts b/jest.config.ts
index 7d4831524d01c3..11663af4e08107 100644
--- a/jest.config.ts
+++ b/jest.config.ts
@@ -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',
diff --git a/package.json b/package.json
index 72b7076ee65d01..f6166c2985a30c 100644
--- a/package.json
+++ b/package.json
@@ -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",
@@ -85,11 +85,18 @@
"eslint --ext .ts"
]
},
- "packageManager": "pnpm@6.30.0",
+ "packageManager": "pnpm@6.32.3",
"pnpm": {
"overrides": {
"vite": "workspace:*",
"@vitejs/plugin-vue": "workspace:*"
+ },
+ "packageExtensions": {
+ "postcss-load-config": {
+ "peerDependencies": {
+ "postcss": "*"
+ }
+ }
}
}
}
diff --git a/packages/create-vite/CHANGELOG.md b/packages/create-vite/CHANGELOG.md
index b81d7ec6fac49a..bf69fae7e535ad 100644
--- a/packages/create-vite/CHANGELOG.md
+++ b/packages/create-vite/CHANGELOG.md
@@ -1,3 +1,12 @@
+## 2.9.0 (2022-03-30)
+
+* chore: add isolatedModules to create-vite > template-vue-ts > tsconfig (#7304) ([21990ea](https://github.com/vitejs/vite/commit/21990ea)), closes [#7304](https://github.com/vitejs/vite/issues/7304)
+* chore(deps): update all non-major dependencies (#7490) ([42c15f6](https://github.com/vitejs/vite/commit/42c15f6)), closes [#7490](https://github.com/vitejs/vite/issues/7490)
+* docs(vue-ts): update note on vue type support in ts (#6165) ([cfc7648](https://github.com/vitejs/vite/commit/cfc7648)), closes [#6165](https://github.com/vitejs/vite/issues/6165)
+* workflow: separate version bumping and publishing on release (#6879) ([fe8ef39](https://github.com/vitejs/vite/commit/fe8ef39)), closes [#6879](https://github.com/vitejs/vite/issues/6879)
+
+
+
# [2.8.0](https://github.com/vitejs/vite/compare/create-vite@2.7.2...create-vite@2.8.0) (2022-02-09)
diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json
index 5d873b83fe515b..72955697360477 100644
--- a/packages/create-vite/package.json
+++ b/packages/create-vite/package.json
@@ -1,6 +1,6 @@
{
"name": "create-vite",
- "version": "2.8.0",
+ "version": "2.9.0",
"license": "MIT",
"author": "Evan You",
"bin": {
@@ -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"
}
}
diff --git a/packages/create-vite/template-lit-ts/package.json b/packages/create-vite/template-lit-ts/package.json
index 5c0a7c7948ee58..061def321a22e6 100644
--- a/packages/create-vite/template-lit-ts/package.json
+++ b/packages/create-vite/template-lit-ts/package.json
@@ -19,7 +19,7 @@
"lit": "^2.0.2"
},
"devDependencies": {
- "vite": "^2.8.0",
+ "vite": "^2.9.0",
"typescript": "^4.5.4"
}
}
diff --git a/packages/create-vite/template-lit/package.json b/packages/create-vite/template-lit/package.json
index ca3c71428f22c9..89f4fee41576c6 100644
--- a/packages/create-vite/template-lit/package.json
+++ b/packages/create-vite/template-lit/package.json
@@ -17,6 +17,6 @@
"lit": "^2.0.2"
},
"devDependencies": {
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-preact-ts/package.json b/packages/create-vite/template-preact-ts/package.json
index df1726ba6c4f7b..dfa6659650c5ae 100644
--- a/packages/create-vite/template-preact-ts/package.json
+++ b/packages/create-vite/template-preact-ts/package.json
@@ -13,6 +13,6 @@
"devDependencies": {
"@preact/preset-vite": "^2.1.5",
"typescript": "^4.5.4",
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-preact/package.json b/packages/create-vite/template-preact/package.json
index 2865df70374acf..02528128f6442e 100644
--- a/packages/create-vite/template-preact/package.json
+++ b/packages/create-vite/template-preact/package.json
@@ -12,6 +12,6 @@
},
"devDependencies": {
"@preact/preset-vite": "^2.1.5",
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json
index 3b1e21b7dbca8c..00f99c8669d660 100644
--- a/packages/create-vite/template-react-ts/package.json
+++ b/packages/create-vite/template-react-ts/package.json
@@ -16,6 +16,6 @@
"@types/react-dom": "^17.0.10",
"@vitejs/plugin-react": "^1.0.7",
"typescript": "^4.5.4",
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json
index 7b0f87c6bc95f5..f6a93540f0d3ee 100644
--- a/packages/create-vite/template-react/package.json
+++ b/packages/create-vite/template-react/package.json
@@ -13,6 +13,6 @@
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.7",
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-svelte-ts/README.md b/packages/create-vite/template-svelte-ts/README.md
index a9d516a32c682e..4ef762ffec4df3 100644
--- a/packages/create-vite/template-svelte-ts/README.md
+++ b/packages/create-vite/template-svelte-ts/README.md
@@ -4,7 +4,7 @@ This template should help get you started developing with Svelte and TypeScript
## Recommended IDE Setup
-[VSCode](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
+[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
## Need an official Svelte framework?
diff --git a/packages/create-vite/template-svelte-ts/package.json b/packages/create-vite/template-svelte-ts/package.json
index 3f2c63759285e5..32e080146e0b6e 100644
--- a/packages/create-vite/template-svelte-ts/package.json
+++ b/packages/create-vite/template-svelte-ts/package.json
@@ -17,6 +17,6 @@
"svelte-preprocess": "^4.9.8",
"tslib": "^2.3.1",
"typescript": "^4.5.4",
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-svelte/README.md b/packages/create-vite/template-svelte/README.md
index 8e35d33d2bc7c8..50ea7ed3b9132d 100644
--- a/packages/create-vite/template-svelte/README.md
+++ b/packages/create-vite/template-svelte/README.md
@@ -4,7 +4,7 @@ This template should help get you started developing with Svelte in Vite.
## Recommended IDE Setup
-[VSCode](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
+[VS Code](https://code.visualstudio.com/) + [Svelte](https://marketplace.visualstudio.com/items?itemName=svelte.svelte-vscode).
## Need an official Svelte framework?
diff --git a/packages/create-vite/template-svelte/package.json b/packages/create-vite/template-svelte/package.json
index e81ffa8288b6ef..da049c170731b9 100644
--- a/packages/create-vite/template-svelte/package.json
+++ b/packages/create-vite/template-svelte/package.json
@@ -11,6 +11,6 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
"svelte": "^3.44.0",
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-vanilla-ts/package.json b/packages/create-vite/template-vanilla-ts/package.json
index 9b6cc582bfdb11..8dd7a0bb800909 100644
--- a/packages/create-vite/template-vanilla-ts/package.json
+++ b/packages/create-vite/template-vanilla-ts/package.json
@@ -9,6 +9,6 @@
},
"devDependencies": {
"typescript": "^4.5.4",
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-vanilla/package.json b/packages/create-vite/template-vanilla/package.json
index f409412bbdc272..ff318e00f14fd1 100644
--- a/packages/create-vite/template-vanilla/package.json
+++ b/packages/create-vite/template-vanilla/package.json
@@ -8,6 +8,6 @@
"preview": "vite preview"
},
"devDependencies": {
- "vite": "^2.8.0"
+ "vite": "^2.9.0"
}
}
diff --git a/packages/create-vite/template-vue-ts/README.md b/packages/create-vite/template-vue-ts/README.md
index f5342b7d8f66dd..e432516724c1a7 100644
--- a/packages/create-vite/template-vue-ts/README.md
+++ b/packages/create-vite/template-vue-ts/README.md
@@ -1,11 +1,16 @@
-# Vue 3 + Typescript + Vite
+# Vue 3 + TypeScript + Vite
-This template should help get you started developing with Vue 3 and Typescript in Vite. The template uses Vue 3 `
+
+
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('linked css', async () => {
+ const res = await page.request.get(
+ new URL('./linked.css', page.url()).href,
+ {
+ headers: {
+ accept: 'text/css'
+ }
+ }
+ )
+ const css = await res.text()
+ const lines = css.split('\n')
+ expect(lines[lines.length - 1].includes('/*')).toBe(false) // expect no sourcemap
+ })
+
+ test('linked css with import', async () => {
+ const res = await page.request.get(
+ new URL('./linked-with-import.css', page.url()).href,
+ {
+ headers: {
+ accept: 'text/css'
+ }
+ }
+ )
+ const css = await res.text()
+ const map = extractSourcemap(css)
+ expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
+ Object {
+ "mappings": "AAAA;EACE,UAAU;AACZ;;ACAA;EACE,UAAU;AACZ",
+ "sources": Array [
+ "/root/be-imported.css",
+ "/root/linked-with-import.css",
+ ],
+ "sourcesContent": Array [
+ ".be-imported {
+ color: red;
+ }
+ ",
+ "@import '@/be-imported.css';
+
+ .linked-with-import {
+ color: red;
+ }
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('imported css', async () => {
+ const css = await getStyleTagContentIncluding('.imported ')
+ const map = extractSourcemap(css)
+ expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
+ Object {
+ "mappings": "AAAA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACX,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACb,CAAC;",
+ "sources": Array [
+ "/root/imported.css",
+ ],
+ "sourcesContent": Array [
+ ".imported {
+ color: red;
+ }
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('imported css with import', async () => {
+ const css = await getStyleTagContentIncluding('.imported-with-import ')
+ const map = extractSourcemap(css)
+ expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
+ Object {
+ "mappings": "AAAA;EACE,UAAU;AACZ;;ACAA;EACE,UAAU;AACZ",
+ "sources": Array [
+ "/root/be-imported.css",
+ "/root/imported-with-import.css",
+ ],
+ "sourcesContent": Array [
+ ".be-imported {
+ color: red;
+ }
+ ",
+ "@import '@/be-imported.css';
+
+ .imported-with-import {
+ color: red;
+ }
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('imported sass', async () => {
+ const css = await getStyleTagContentIncluding('.imported-sass ')
+ const map = extractSourcemap(css)
+ expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
+ Object {
+ "mappings": "AACE;EACE",
+ "sources": Array [
+ "/root/imported.sass",
+ ],
+ "sourcesContent": Array [
+ ".imported
+ &-sass
+ color: red
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('imported sass module', async () => {
+ const css = await getStyleTagContentIncluding('._imported-sass-module_')
+ const map = extractSourcemap(css)
+ expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
+ Object {
+ "mappings": "AACE;EACE",
+ "sources": Array [
+ "/root/imported.module.sass",
+ ],
+ "sourcesContent": Array [
+ ".imported
+ &-sass-module
+ color: red
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('imported less', async () => {
+ const css = await getStyleTagContentIncluding('.imported-less ')
+ const map = extractSourcemap(css)
+ expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
+ Object {
+ "mappings": "AACE;EACE",
+ "sources": Array [
+ "/root/imported.less",
+ ],
+ "sourcesContent": Array [
+ ".imported {
+ &-less {
+ color: @color;
+ }
+ }
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('imported stylus', async () => {
+ const css = await getStyleTagContentIncluding('.imported-stylus ')
+ const map = extractSourcemap(css)
+ expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
+ Object {
+ "mappings": "AACE;EACE,cAAM",
+ "sources": Array [
+ "/root/imported.styl",
+ ],
+ "sourcesContent": Array [
+ ".imported
+ &-stylus
+ color blue-red-mixed
+ ",
+ ],
+ "version": 3,
+ }
+ `)
+ })
+
+ test('should not output missing source file warning', () => {
+ serverLogs.forEach((log) => {
+ expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/)
+ })
+ })
+} else {
+ test('this file only includes test for serve', () => {
+ expect(true).toBe(true)
+ })
+}
diff --git a/packages/playground/css-sourcemap/be-imported.css b/packages/playground/css-sourcemap/be-imported.css
new file mode 100644
index 00000000000000..a29e5f77e3cb5d
--- /dev/null
+++ b/packages/playground/css-sourcemap/be-imported.css
@@ -0,0 +1,3 @@
+.be-imported {
+ color: red;
+}
diff --git a/packages/playground/css-sourcemap/imported-with-import.css b/packages/playground/css-sourcemap/imported-with-import.css
new file mode 100644
index 00000000000000..6a1ed3c3772698
--- /dev/null
+++ b/packages/playground/css-sourcemap/imported-with-import.css
@@ -0,0 +1,5 @@
+@import '@/be-imported.css';
+
+.imported-with-import {
+ color: red;
+}
diff --git a/packages/playground/css-sourcemap/imported.css b/packages/playground/css-sourcemap/imported.css
new file mode 100644
index 00000000000000..9c9b32924962dc
--- /dev/null
+++ b/packages/playground/css-sourcemap/imported.css
@@ -0,0 +1,3 @@
+.imported {
+ color: red;
+}
diff --git a/packages/playground/css-sourcemap/imported.less b/packages/playground/css-sourcemap/imported.less
new file mode 100644
index 00000000000000..e71b15eb102441
--- /dev/null
+++ b/packages/playground/css-sourcemap/imported.less
@@ -0,0 +1,5 @@
+.imported {
+ &-less {
+ color: @color;
+ }
+}
diff --git a/packages/playground/css-sourcemap/imported.module.sass b/packages/playground/css-sourcemap/imported.module.sass
new file mode 100644
index 00000000000000..448a5e7e31f75a
--- /dev/null
+++ b/packages/playground/css-sourcemap/imported.module.sass
@@ -0,0 +1,3 @@
+.imported
+ &-sass-module
+ color: red
diff --git a/packages/playground/css-sourcemap/imported.sass b/packages/playground/css-sourcemap/imported.sass
new file mode 100644
index 00000000000000..06fa634d5dd4e9
--- /dev/null
+++ b/packages/playground/css-sourcemap/imported.sass
@@ -0,0 +1,3 @@
+.imported
+ &-sass
+ color: red
diff --git a/packages/playground/css-sourcemap/imported.styl b/packages/playground/css-sourcemap/imported.styl
new file mode 100644
index 00000000000000..83c7cf517acf4d
--- /dev/null
+++ b/packages/playground/css-sourcemap/imported.styl
@@ -0,0 +1,3 @@
+.imported
+ &-stylus
+ color blue-red-mixed
diff --git a/packages/playground/css-sourcemap/index.html b/packages/playground/css-sourcemap/index.html
new file mode 100644
index 00000000000000..a943c1d113a9b4
--- /dev/null
+++ b/packages/playground/css-sourcemap/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+
Deep import with exports field + exposed directory
fail
@@ -38,12 +41,35 @@
fail
+
+ A ts module can import another tsx module using its corresponding jsx file
+ name
+
+
fail
+
+
+ A ts module can import another tsx module using its corresponding js file name
+
+
fail
+
Resolve file name containing dot
fail
Browser Field
fail
+
+ Resolve to the `browser` field instead of `module` when the importer is a
+ `require` call
+
+
fail
+
+
+ Resolve to the `main` field instead of `module` when the importer is a
+ `require` call
+
+
fail
+
CSS Entry
@@ -100,6 +126,10 @@
resolve package that contains # in path
import { msg as deepMsg } from 'resolve-exports-path/deep.js'
text('.exports-deep', deepMsg)
+ // deep import w/ exports w/ query
+ import deepPath from 'resolve-exports-path/deep.json?url'
+ text('.exports-deep-query', deepPath)
+
// deep import w/ exposed dir
import { msg as exposedDirMsg } from 'resolve-exports-path/dir/dir'
text('.exports-deep-exposed-dir', exposedDirMsg)
@@ -130,6 +160,12 @@
resolve package that contains # in path
import { msg as tsExtensionMsg } from './ts-extension'
text('.ts-extension', tsExtensionMsg)
+ import { msgJsx as tsJsxExtensionMsg } from './ts-extension'
+ text('.jsx-extension', tsJsxExtensionMsg)
+
+ import { msgTsx as tsTsxExtensionMsg } from './ts-extension'
+ text('.tsx-extension', tsTsxExtensionMsg)
+
// filename with dot
import { bar } from './util/bar.util'
text('.dot', bar())
@@ -144,10 +180,11 @@
resolve package that contains # in path
import e from 'resolve-browser-field/ext-index/index.js'
import f from 'resolve-browser-field/ext-index'
import g from 'resolve-browser-field/no-ext-index/index.js' // no substitution
+ import h from 'resolve-browser-field/no-ext?query'
import { ra, rb, rc, rd, re, rf, rg } from 'resolve-browser-field/relative'
- const success = [main, a, c, d, e, f, ra, rc, rd, re, rf]
+ const success = [main, a, c, d, e, f, h, ra, rc, rd, re, rf]
const noSuccess = [b, g, rb, rg]
if (
@@ -157,6 +194,12 @@
resolve package that contains # in path
text('.browser', main)
}
+ import { msg as requireBrowserMsg } from 'require-pkg-with-browser-and-module-field'
+ text('.require-pkg-with-browser-and-module-field', requireBrowserMsg)
+
+ import { msg as requireMainMsg } from 'require-pkg-with-esm-entries'
+ text('.require-pkg-with-esm-entries', requireMainMsg)
+
import { msg as customExtMsg } from './custom-ext'
text('.custom-ext', customExtMsg)
diff --git a/packages/playground/resolve/package.json b/packages/playground/resolve/package.json
index 5e0f53b4c8468a..4b8d497b3dbb27 100644
--- a/packages/playground/resolve/package.json
+++ b/packages/playground/resolve/package.json
@@ -12,6 +12,8 @@
"@babel/runtime": "^7.16.0",
"es5-ext": "0.10.53",
"normalize.css": "^8.0.1",
+ "require-pkg-with-browser-and-module-field": "link:./require-pkg-with-browser-and-module-field",
+ "require-pkg-with-esm-entries": "link:./require-pkg-with-esm-entries",
"resolve-browser-field": "link:./browser-field",
"resolve-custom-condition": "link:./custom-condition",
"resolve-custom-main-field": "link:./custom-main-field",
diff --git a/packages/playground/resolve/require-pkg-with-browser-and-module-field/dep.cjs b/packages/playground/resolve/require-pkg-with-browser-and-module-field/dep.cjs
new file mode 100644
index 00000000000000..3fb20b76d48b79
--- /dev/null
+++ b/packages/playground/resolve/require-pkg-with-browser-and-module-field/dep.cjs
@@ -0,0 +1,5 @@
+const BigNumber = require('bignumber.js')
+
+const x = new BigNumber('1111222233334444555566')
+
+module.exports = x.toString()
diff --git a/packages/playground/resolve/require-pkg-with-browser-and-module-field/index.cjs b/packages/playground/resolve/require-pkg-with-browser-and-module-field/index.cjs
new file mode 100644
index 00000000000000..86d3360ab38dcb
--- /dev/null
+++ b/packages/playground/resolve/require-pkg-with-browser-and-module-field/index.cjs
@@ -0,0 +1,8 @@
+const dep = require('./dep.cjs')
+
+const msg =
+ dep === '1.111222233334444555566e+21'
+ ? '[success] require-pkg-with-browser-and-module-field'
+ : '[failed] require-pkg-with-browser-and-module-field'
+
+exports.msg = msg
diff --git a/packages/playground/resolve/require-pkg-with-browser-and-module-field/package.json b/packages/playground/resolve/require-pkg-with-browser-and-module-field/package.json
new file mode 100644
index 00000000000000..2a0419b331c407
--- /dev/null
+++ b/packages/playground/resolve/require-pkg-with-browser-and-module-field/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "require-pkg-with-browser-and-module-field",
+ "private": true,
+ "version": "1.0.0",
+ "main": "./index.cjs",
+ "dependencies": {
+ "bignumber.js": "9.0.2"
+ }
+}
diff --git a/packages/playground/resolve/require-pkg-with-esm-entries/index.cjs b/packages/playground/resolve/require-pkg-with-esm-entries/index.cjs
new file mode 100644
index 00000000000000..55958fbdba26ee
--- /dev/null
+++ b/packages/playground/resolve/require-pkg-with-esm-entries/index.cjs
@@ -0,0 +1,9 @@
+const fromEvent = require('callbag-from-event')
+
+const msg =
+ // should be the exported function instead of the ES Module record (`{ default: ... }`)
+ typeof fromEvent === 'function'
+ ? '[success] require-pkg-with-esm-entries'
+ : '[failed] require-pkg-with-esm-entries'
+
+exports.msg = msg
diff --git a/packages/playground/resolve/require-pkg-with-esm-entries/package.json b/packages/playground/resolve/require-pkg-with-esm-entries/package.json
new file mode 100644
index 00000000000000..b845364bb6f19a
--- /dev/null
+++ b/packages/playground/resolve/require-pkg-with-esm-entries/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "require-pkg-with-esm-entries",
+ "private": true,
+ "version": "1.0.0",
+ "main": "./index.cjs",
+ "dependencies": {
+ "callbag-from-event": "1.3.0"
+ }
+}
diff --git a/packages/playground/resolve/ts-extension/hellojsx.tsx b/packages/playground/resolve/ts-extension/hellojsx.tsx
new file mode 100644
index 00000000000000..a8f610b399b17a
--- /dev/null
+++ b/packages/playground/resolve/ts-extension/hellojsx.tsx
@@ -0,0 +1 @@
+export const msgJsx = '[success] use .jsx extension to import a tsx module'
diff --git a/packages/playground/resolve/ts-extension/hellotsx.tsx b/packages/playground/resolve/ts-extension/hellotsx.tsx
new file mode 100644
index 00000000000000..b7461ca71ded6c
--- /dev/null
+++ b/packages/playground/resolve/ts-extension/hellotsx.tsx
@@ -0,0 +1 @@
+export const msgTsx = '[success] use .js extension to import a tsx module'
diff --git a/packages/playground/resolve/ts-extension/index.ts b/packages/playground/resolve/ts-extension/index.ts
index e095619ee4d716..bdb326f8778e64 100644
--- a/packages/playground/resolve/ts-extension/index.ts
+++ b/packages/playground/resolve/ts-extension/index.ts
@@ -1,3 +1,5 @@
import { msg } from './hello.js'
+import { msgJsx } from './hellojsx.jsx'
+import { msgTsx } from './hellotsx.js'
-export { msg }
+export { msg, msgJsx, msgTsx }
diff --git a/packages/playground/resolve/vite.config.js b/packages/playground/resolve/vite.config.js
index be1b75e431383a..c1282f4ffc789d 100644
--- a/packages/playground/resolve/vite.config.js
+++ b/packages/playground/resolve/vite.config.js
@@ -40,5 +40,11 @@ module.exports = {
}
}
}
- ]
+ ],
+ optimizeDeps: {
+ include: [
+ 'require-pkg-with-browser-and-module-field',
+ 'require-pkg-with-esm-entries'
+ ]
+ }
}
diff --git a/packages/playground/tailwind-sourcemap/__tests__/build.spec.ts b/packages/playground/tailwind-sourcemap/__tests__/build.spec.ts
new file mode 100644
index 00000000000000..e36c1f52d2c1f8
--- /dev/null
+++ b/packages/playground/tailwind-sourcemap/__tests__/build.spec.ts
@@ -0,0 +1,13 @@
+import { isBuild } from 'testUtils'
+
+if (isBuild) {
+ test('should not output sourcemap warning (#4939)', () => {
+ serverLogs.forEach((log) => {
+ expect(log).not.toMatch('Sourcemap is likely to be incorrect')
+ })
+ })
+} else {
+ test('this file only includes test for build', () => {
+ expect(true).toBe(true)
+ })
+}
diff --git a/packages/playground/tailwind-sourcemap/__tests__/serve.spec.ts b/packages/playground/tailwind-sourcemap/__tests__/serve.spec.ts
new file mode 100644
index 00000000000000..d961f75e4536e5
--- /dev/null
+++ b/packages/playground/tailwind-sourcemap/__tests__/serve.spec.ts
@@ -0,0 +1,13 @@
+import { isBuild } from 'testUtils'
+
+if (!isBuild) {
+ test('should not output missing source file warning', () => {
+ serverLogs.forEach((log) => {
+ expect(log).not.toMatch(/Sourcemap for .+ points to missing source files/)
+ })
+ })
+} else {
+ test('this file only includes test for serve', () => {
+ expect(true).toBe(true)
+ })
+}
diff --git a/packages/playground/tailwind-sourcemap/index.html b/packages/playground/tailwind-sourcemap/index.html
new file mode 100644
index 00000000000000..95c8c5da7716d1
--- /dev/null
+++ b/packages/playground/tailwind-sourcemap/index.html
@@ -0,0 +1,9 @@
+