diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index 48a0bd7773b0d7..beab59a2df5ac9 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -63,7 +63,7 @@ module.exports = defineConfig({
'node/no-extraneous-import': [
'error',
{
- allowModules: ['vite', 'less', 'sass']
+ allowModules: ['vite', 'less', 'sass', 'vitest']
}
],
'node/no-extraneous-require': [
@@ -103,13 +103,13 @@ module.exports = defineConfig({
}
},
{
- files: ['packages/vite/types/**'],
+ files: ['packages/vite/types/**', '*.spec.ts'],
rules: {
'node/no-extraneous-import': 'off'
}
},
{
- files: ['packages/playground/**'],
+ files: ['playground/**'],
rules: {
'node/no-extraneous-import': 'off',
'node/no-extraneous-require': 'off'
diff --git a/.github/renovate.json5 b/.github/renovate.json5
index 06fe0e7ea2aaff..17898db2741284 100644
--- a/.github/renovate.json5
+++ b/.github/renovate.json5
@@ -1,11 +1,7 @@
{
"extends": ["config:base", "schedule:weekly", "group:allNonMajor"],
"labels": ["dependencies"],
- "ignorePaths": [
- "packages/playground/**",
- "packages/create-vite/template-*/**",
- "**/__tests__/**"
- ],
+ "ignorePaths": ["**/__tests__/**"],
"pin": false,
"rangeStrategy": "bump",
"node": false,
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index cde7dfb03825ed..b1c663db40e80f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -13,6 +13,8 @@ on:
- feat/*
- fix/*
- perf/*
+ - v1
+ - v2
pull_request:
workflow_dispatch:
@@ -27,12 +29,17 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
- node_version: [12, 14, 16, 17]
+ node_version: [14, 16, 18]
include:
- os: macos-latest
node_version: 16
+ - os: macos-latest
+ node_version: 18
- os: windows-latest
node_version: 16
+ # Maybe bug with jest on windows and node-v18
+ # - os: windows-latest
+ # node_version: 18
fail-fast: false
name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
@@ -42,8 +49,6 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
- with:
- version: 6
- name: Set node version to ${{ matrix.node_version }}
uses: actions/setup-node@v3
@@ -63,6 +68,9 @@ jobs:
- name: Build plugin-react
run: pnpm run build-plugin-react
+ - name: Test unit
+ run: pnpm run test-unit
+
- name: Test serve
run: pnpm run test-serve -- --runInBand
@@ -80,8 +88,6 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
- with:
- version: 6
- name: Set node version to 16
uses: actions/setup-node@v3
diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml
new file mode 100644
index 00000000000000..df554b38e75246
--- /dev/null
+++ b/.github/workflows/semantic-pull-request.yml
@@ -0,0 +1,18 @@
+name: Semantic Pull Request
+
+on:
+ pull_request_target:
+ types:
+ - opened
+ - edited
+ - synchronize
+
+jobs:
+ main:
+ runs-on: ubuntu-latest
+ name: Semantic Pull Request
+ steps:
+ - name: Validate PR title
+ uses: amannn/action-semantic-pull-request@v4
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/.gitignore b/.gitignore
index 44abdd7bf563db..9194d44b544c4e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,14 +1,15 @@
-.DS_Store
-node_modules
!**/glob-import/dir/node_modules
-dist
-dist-ssr
-TODOs.md
-*.log
-temp
-explorations
+.DS_Store
.idea
-*.local
-/packages/vite/LICENSE
*.cpuprofile
+*.local
+*.log
/.vscode/
+/packages/vite/LICENSE
+dist
+dist-ssr
+explorations
+node_modules
+playground-temp
+temp
+TODOs.md
diff --git a/.prettierignore b/.prettierignore
index c624a3a21eecfe..ad4762a457c436 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -8,6 +8,6 @@ LICENSE.md
.prettierignore
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
+playground/tsconfig-json-load-error/has-error/tsconfig.json
+playground/html/invalid.html
+playground/worker/classic-worker.js
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index a87561a8e4146c..e620377c75408f 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -24,9 +24,9 @@ If you want to use break point and explore code execution you can use the ["Run
2. Click on the "Run and Debug" icon in the activity bar of the editor.
-3. Click on the "Javascript Debug Terminal" button.
+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`.
+4. It will open a terminal, then go to `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...
@@ -42,7 +42,7 @@ Some errors are masked and hidden away because of the layers of abstraction and
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. Focusing the Chromium 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.
@@ -67,22 +67,32 @@ And re-run `pnpm install` to link the package.
## Running Tests
-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.
+### Integration Tests
-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 package under `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.
-Each test can be run under either dev server mode or build mode.
+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). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242).
-- `pnpm test` by default runs every test in both serve and build mode.
+Each integration test can be run under either dev server mode or build mode.
+
+- `pnpm test` by default runs every integration test in both serve and build mode, and also unit tests.
- `pnpm run test-serve` runs tests only under serve mode. This is just calling `jest` so you can pass any Jest flags to this command. Since Jest will attempt to run tests in parallel, if your machine has many cores this may cause flaky test failures with multiple Playwright instances running at the same time. You can force the tests to run in series with `pnpm run test-serve -- --runInBand`.
- `pnpm run test-build` runs tests only under build mode.
-- You can also use `pnpm run test-serve -- [match]` or `pnpm run test-build -- [match]` to run tests in a specific playground package, e.g. `pnpm run test-serve -- css` will run tests for both `playground/css` and `playground/css-codesplit` under serve mode.
+- You can also use `pnpm run test-serve -- [match]` or `pnpm run test-build -- [match]` to run tests in a specific playground package, e.g. `pnpm run test-serve -- asset` will run tests for both `playground/asset` and `vite/src/node/__tests__/asset` under serve mode and `vite/src/node/__tests__/**/*` just run in serve mode.
Note package matching is not available for the `pnpm test` script, which always runs all tests.
+### Unit Tests
+
+Other than tests under `playground/` for integration tests, packages might contains unit tests under their `__tests__` directory. Unit tests are powered by [Vitest](https://vitest.dev/). The detailed config is inside `vitest.config.ts` files.
+
+- `pnpm run test-unit` runs unit tests under each package.
+
+- You can also use `pnpm run test-unit -- [match]` to run related tests.
+
### Test Env and Helpers
Inside playground tests, a global `page` object is automatically available, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as:
@@ -93,18 +103,20 @@ test('should work', async () => {
})
```
-Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `packages/playground/testUtils.ts`.
+Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `playground/testUtils.ts`.
+
+Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/jestPerTestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.
### Extending the Test Suite
-To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/packages/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L121):
+To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/playground/assets/index.html#L121):
```html
?raw import
```
-This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L151):
+This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L151):
```js
import rawSvg from './nested/fragment.svg?raw'
@@ -119,7 +131,7 @@ function text(el, text) {
}
```
-In the [spec tests](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
+In the [spec tests](https://github.com/vitejs/vite/blob/main/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
```js
test('?raw import', async () => {
@@ -136,7 +148,7 @@ To work around this, playground packages that uses the `file:` protocol should a
```jsonc
"scripts": {
//...
- "postinstall": "ts-node ../../../scripts/patchFileDeps.ts"
+ "postinstall": "ts-node ../../scripts/patchFileDeps.ts"
}
```
@@ -229,7 +241,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`
@@ -238,7 +250,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/README.md b/README.md
index 546014a12c7116..a6f13829f2635f 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,8 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g
## Packages
+> This branch is for the upcoming v3.0, if you are looking for current stable releases, check the [`v2` branch](https://github.com/vitejs/vite/tree/v2) instead.
+
| Package | Version (click for changelogs) |
| ------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- |
| [vite](packages/vite) | [![vite version](https://img.shields.io/npm/v/vite.svg?label=%20)](packages/vite/CHANGELOG.md) |
diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.ts
similarity index 94%
rename from docs/.vitepress/config.js
rename to docs/.vitepress/config.ts
index ee76a29986d3fb..4659ea5ab7ae4f 100644
--- a/docs/.vitepress/config.js
+++ b/docs/.vitepress/config.ts
@@ -1,9 +1,6 @@
-// @ts-check
+import { defineConfig } from 'vitepress'
-/**
- * @type {import('vitepress').UserConfig}
- */
-module.exports = {
+export default defineConfig({
title: 'Vite',
description: 'Next Generation Frontend Tooling',
head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]],
@@ -64,6 +61,15 @@ module.exports = {
}
]
},
+ {
+ text: 'v3 (next)',
+ items: [
+ {
+ text: 'v2.x (stable)',
+ link: 'https://v2.vitejs.dev'
+ }
+ ]
+ },
{
text: 'Languages',
items: [
@@ -169,4 +175,4 @@ module.exports = {
]
}
}
-}
+})
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 9fc9273c691f56..5862419405aa89 100644
--- a/docs/config/index.md
+++ b/docs/config/index.md
@@ -28,7 +28,7 @@ vite --config my-config.js
```
::: 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:
+Vite will replace `__filename`, `__dirname`, and `import.meta.url` in config files and its deps. Using these as variable names will result in an error:
```js
const __filename = "value"
@@ -94,23 +94,29 @@ If the config needs to call async function, it can export a async function inste
export default defineConfig(async ({ command, mode }) => {
const data = await asyncFunction()
return {
- // build specific config
+ // vite config
}
})
```
### 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.
+Environmental Variables can be obtained from `process.env` as usual.
+
+Note that 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())
+ // Load env file based on `mode` in the current working directory.
+ // Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
+ const env = loadEnv(mode, process.cwd(), '')
return {
- // build specific config
+ // vite config
+ define: {
+ __APP_ENV__: env.APP_ENV
+ }
}
})
```
@@ -158,7 +164,7 @@ export default defineConfig(({ command, mode }) => {
- 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`).
+ - Replacements are performed only when the match isn't surrounded by other letters, numbers, `_` or `$`.
::: warning
Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only.
@@ -235,7 +241,7 @@ export default defineConfig(({ command, mode }) => {
{
"exports": {
".": {
- "import": "./index.esm.js",
+ "import": "./index.esm.mjs",
"require": "./index.cjs.js"
}
}
@@ -304,7 +310,11 @@ export default defineConfig(({ command, mode }) => {
- **Type:** `string | (postcss.ProcessOptions & { plugins?: postcss.Plugin[] })`
- 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.
+ Inline PostCSS config or a custom directory to search PostCSS config from (default is project root).
+
+ For inline PostCSS config, it expects the same format as `postcss.config.js`. But for `plugins` property, only [array format](https://github.com/postcss/postcss-load-config/blob/main/README.md#array) can be used.
+
+ 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.
@@ -357,7 +367,7 @@ export default defineConfig(({ 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({
@@ -368,9 +378,9 @@ 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`, which can be a regex, a [picomatch](https://github.com/micromatch/picomatch#globbing-features) pattern, or an array of either.
+ 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({
@@ -380,7 +390,7 @@ export default defineConfig(({ command, mode }) => {
})
```
- Set to `false` to disable ESbuild transforms.
+ Set to `false` to disable esbuild transforms.
### assetsInclude
@@ -700,7 +710,7 @@ Defines the origin of the generated asset URLs during development.
```js
export default defineConfig({
server: {
- origin: 'http://127.0.0.1:8080/'
+ origin: 'http://127.0.0.1:8080'
}
})
```
@@ -849,7 +859,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.
@@ -1012,7 +1022,6 @@ export default defineConfig({
- `external` is also omitted, use Vite's `optimizeDeps.exclude` option
- `plugins` are merged with Vite's dep plugin
- - `keepNames` takes precedence over the deprecated `optimizeDeps.keepNames`
## SSR Options
diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md
index 46eabab04e8868..1cba492e6613c1 100644
--- a/docs/guide/api-hmr.md
+++ b/docs/guide/api-hmr.md
@@ -10,21 +10,27 @@ Vite exposes its manual HMR API via the special `import.meta.hot` object:
```ts
interface ImportMeta {
- readonly hot?: {
- readonly data: any
+ readonly hot?: ViteHotContext
+}
+
+interface ViteHotContext {
+ readonly data: any
- accept(): void
- accept(cb: (mod: any) => void): void
- accept(dep: string, cb: (mod: any) => void): void
- accept(deps: string[], cb: (mods: any[]) => void): void
+ accept(): void
+ accept(cb: (mod: any) => void): void
+ accept(dep: string, cb: (mod: any) => void): void
+ accept(deps: readonly string[], cb: (mods: any[]) => void): void
- prune(cb: () => void): void
- dispose(cb: (data: any) => void): void
- decline(): void
- invalidate(): void
+ dispose(cb: (data: any) => void): void
+ decline(): void
+ invalidate(): void
- on(event: string, cb: (...args: any[]) => void): void
- }
+ // `InferCustomEventPayload` provides types for built-in Vite events
+ on(
+ event: T,
+ cb: (payload: InferCustomEventPayload) => void
+ ): void
+ send(event: T, data?: InferCustomEventPayload): void
}
```
diff --git a/docs/guide/api-javascript.md b/docs/guide/api-javascript.md
index ddaa04279737f5..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`
diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md
index 4a5b1c07c7893e..76b9984a069828 100644
--- a/docs/guide/api-plugin.md
+++ b/docs/guide/api-plugin.md
@@ -113,7 +113,7 @@ Virtual modules are a useful scheme that allows you to pass build time informati
```js
export default function myPlugin() {
- const virtualModuleId = '@my-virtual-module'
+ const virtualModuleId = 'virtual:my-module'
const resolvedVirtualModuleId = '\0' + virtualModuleId
return {
@@ -135,7 +135,7 @@ export default function myPlugin() {
Which allows importing the module in JavaScript:
```js
-import { msg } from '@my-virtual-module'
+import { msg } from 'virtual:my-module'
console.log(msg)
```
@@ -186,8 +186,10 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
const partialConfigPlugin = () => ({
name: 'return-partial',
config: () => ({
- alias: {
- foo: 'bar'
+ resolve: {
+ alias: {
+ foo: 'bar'
+ }
}
})
})
@@ -303,6 +305,28 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
Note `configureServer` is not called when running the production build so your other hooks need to guard against its absence.
+### `configurePreviewServer`
+
+- **Type:** `(server: { middlewares: Connect.Server, httpServer: http.Server }) => (() => void) | void | Promise<(() => void) | void>`
+- **Kind:** `async`, `sequential`
+
+ Same as [`configureServer`](/guide/api-plugin.html#configureserver) but for the preview server. It provides the [connect](https://github.com/senchalabs/connect) server and its underlying [http server](https://nodejs.org/api/http.html). Similarly to `configureServer`, the `configurePreviewServer` hook is called before other middlewares are installed. If you want to inject a middleware **after** other middlewares, you can return a function from `configurePreviewServer`, which will be called after internal middlewares are installed:
+
+ ```js
+ const myPlugin = () => ({
+ name: 'configure-preview-server',
+ configurePreviewServer(server) {
+ // return a post hook that is called after other middlewares are
+ // installed
+ return () => {
+ server.middlewares.use((req, res, next) => {
+ // custom handle request...
+ })
+ }
+ }
+ })
+ ```
+
### `transformIndexHtml`
- **Type:** `IndexHtmlTransformHook | { enforce?: 'pre' | 'post', transform: IndexHtmlTransformHook }`
diff --git a/docs/guide/assets.md b/docs/guide/assets.md
index 53ac153f9465bd..9776dcdd032f35 100644
--- a/docs/guide/assets.md
+++ b/docs/guide/assets.md
@@ -113,3 +113,7 @@ 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.
:::
+
+::: warning Esbuild target config is necessary
+This pattern needs esbuild target to be set to `es2020` or higher. `vite@2.x` use `es2019` as default target. Set [build-target](https://vitejs.dev/config/#build-target) and [optimizedeps.esbuildoptions.target](https://vitejs.dev/config/#optimizedeps-esbuildoptions) to `es2020` or higher if you intend to use this partten.
+:::
diff --git a/docs/guide/build.md b/docs/guide/build.md
index 8216bcbfbac060..358745d02f2cf1 100644
--- a/docs/guide/build.md
+++ b/docs/guide/build.md
@@ -127,7 +127,8 @@ module.exports = defineConfig({
lib: {
entry: path.resolve(__dirname, 'lib/main.js'),
name: 'MyLib',
- fileName: (format) => `my-lib.${format}.js`
+ // the proper extensions will be added
+ fileName: 'my-lib'
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
@@ -159,7 +160,7 @@ Running `vite build` with this config uses a Rollup preset that is oriented towa
```
$ vite build
building for production...
-[write] my-lib.es.js 0.08kb, brotli: 0.07kb
+[write] my-lib.es.mjs 0.08kb, brotli: 0.07kb
[write] my-lib.umd.js 0.30kb, brotli: 0.16kb
```
@@ -170,10 +171,10 @@ Recommended `package.json` for your lib:
"name": "my-lib",
"files": ["dist"],
"main": "./dist/my-lib.umd.js",
- "module": "./dist/my-lib.es.js",
+ "module": "./dist/my-lib.es.mjs",
"exports": {
".": {
- "import": "./dist/my-lib.es.js",
+ "import": "./dist/my-lib.es.mjs",
"require": "./dist/my-lib.umd.js"
}
}
diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md
index 1649feda8c7501..d5f45ea1158808 100644
--- a/docs/guide/env-and-mode.md
+++ b/docs/guide/env-and-mode.md
@@ -42,7 +42,7 @@ In addition, environment variables that already exist when Vite is executed have
`.env` files are loaded at the start of Vite. Restart the server after making changes.
:::
-Loaded env variables are also exposed to your client source code via `import.meta.env`.
+Loaded env variables are also exposed to your client source code via `import.meta.env` as strings.
To prevent accidentally leaking env variables to the client, only variables prefixed with `VITE_` are exposed to your Vite-processed code. e.g. the following file:
@@ -81,6 +81,14 @@ interface ImportMeta {
}
```
+If your code relies on types from browser environments such as [DOM](https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts) and [WebWorker](https://github.com/microsoft/TypeScript/blob/main/lib/lib.webworker.d.ts), you can update the [lib](https://www.typescriptlang.org/tsconfig#lib) field in `tsconfig.json`.
+
+```json
+{
+ "lib": ["WebWorker"]
+}
+```
+
## Modes
By default, the dev server (`dev` command) runs in `development` mode and the `build` command run in `production` mode.
diff --git a/docs/guide/features.md b/docs/guide/features.md
index ebed85cd2d529d..01798ad0d4ea56 100644
--- a/docs/guide/features.md
+++ b/docs/guide/features.md
@@ -53,6 +53,8 @@ It is because `esbuild` only performs transpilation without type information, it
You must set `"isolatedModules": true` in your `tsconfig.json` under `compilerOptions`, so that TS will warn you against the features that do not work with isolated transpilation.
+However, some libraries (e.g. [`vue`](https://github.com/vuejs/core/issues/1228)) don't work well with `"isolatedModules": true`. You can use `"skipLibCheck": true` to temporarily suppress the errors until it is fixed upstream.
+
#### `useDefineForClassFields`
Starting from Vite 2.5.0, the default value will be `true` if the TypeScript target is `ESNext`. It is consistent with the [behavior of `tsc` 4.3.2 and later](https://github.com/microsoft/TypeScript/pull/42663). It is also the standard ECMAScript runtime behavior.
@@ -185,7 +187,7 @@ document.getElementById('foo').className = applyColor
### CSS Pre-processors
-Because Vite targets modern browsers only, it is recommended to use native CSS variables with PostCSS plugins that implement CSSWG drafts (e.g. [postcss-nesting](https://github.com/jonathantneal/postcss-nesting)) and author plain, future-standards-compliant CSS.
+Because Vite targets modern browsers only, it is recommended to use native CSS variables with PostCSS plugins that implement CSSWG drafts (e.g. [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting)) and author plain, future-standards-compliant CSS.
That said, Vite does provide built-in support for `.scss`, `.sass`, `.less`, `.styl` and `.stylus` files. There is no need to install Vite-specific plugins for them, but the corresponding pre-processor itself must be installed:
@@ -280,10 +282,10 @@ for (const path in modules) {
}
```
-Matched files are by default lazy loaded via dynamic import and will be split into separate chunks during build. If you'd rather import all the modules directly (e.g. relying on side-effects in these modules to be applied first), you can use `import.meta.globEager` instead:
+Matched files are by default lazy-loaded via dynamic import and will be split into separate chunks during build. If you'd rather import all the modules directly (e.g. relying on side-effects in these modules to be applied first), you can pass `{ eager: true }` as the second argument:
```js
-const modules = import.meta.globEager('./dir/*.js')
+const modules = import.meta.glob('./dir/*.js', { eager: true })
```
The above will be transformed into the following:
@@ -298,7 +300,9 @@ 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)) with the [Import Reflection](https://github.com/tc39/proposal-import-reflection) syntax:
+### Glob Import As
+
+`import.meta.glob` also supports 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', { as: 'raw' })
@@ -309,18 +313,115 @@ The above will be transformed into the following:
```js
// code produced by vite
const modules = {
- './dir/foo.js': '{\n "msg": "foo"\n}\n',
- './dir/bar.js': '{\n "msg": "bar"\n}\n'
+ './dir/foo.js': 'export default "foo"\n',
+ './dir/bar.js': 'export default "bar"\n'
}
```
+`{ as: 'url' }` is also supported for loading assets as URLs.
+
+### Multiple Patterns
+
+The first argument can be an array of globs, for example
+
+```js
+const modules = import.meta.glob(['./dir/*.js', './another/*.js'])
+```
+
+### Negative Patterns
+
+Negative glob patterns are also supported (prefixed with `!`). To ignore some files from the result, you can add exclude glob patterns to the first argument:
+
+```js
+const modules = import.meta.glob(['./dir/*.js', '!**/bar.js'])
+```
+
+```js
+// code produced by vite
+const modules = {
+ './dir/foo.js': () => import('./dir/foo.js')
+}
+```
+
+#### Named Imports
+
+It's possible to only import parts of the modules with the `import` options.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', { import: 'setup' })
+```
+
+```ts
+// code produced by vite
+const modules = {
+ './dir/foo.js': () => import('./dir/foo.js').then((m) => m.setup),
+ './dir/bar.js': () => import('./dir/bar.js').then((m) => m.setup)
+}
+```
+
+When combined with `eager` it's even possible to have tree-shaking enabled for those modules.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', { import: 'setup', eager: true })
+```
+
+```ts
+// code produced by vite:
+import { setup as __glob__0_0 } from './dir/foo.js'
+import { setup as __glob__0_1 } from './dir/bar.js'
+const modules = {
+ './dir/foo.js': __glob__0_0,
+ './dir/bar.js': __glob__0_1
+}
+```
+
+Set `import` to `default` to import the default export.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', {
+ import: 'default',
+ eager: true
+})
+```
+
+```ts
+// code produced by vite:
+import __glob__0_0 from './dir/foo.js'
+import __glob__0_1 from './dir/bar.js'
+const modules = {
+ './dir/foo.js': __glob__0_0,
+ './dir/bar.js': __glob__0_1
+}
+```
+
+#### Custom Queries
+
+You can also use the `query` option to provide custom queries to imports for other plugins to consume.
+
+```ts
+const modules = import.meta.glob('./dir/*.js', {
+ query: { foo: 'bar', bar: true }
+})
+```
+
+```ts
+// code produced by vite:
+const modules = {
+ './dir/foo.js': () =>
+ import('./dir/foo.js?foo=bar&bar=true').then((m) => m.setup),
+ './dir/bar.js': () =>
+ import('./dir/bar.js?foo=bar&bar=true').then((m) => m.setup)
+}
+```
+
+### Glob Import Caveats
+
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) 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.
+- The glob matching is done via [`fast-glob`](https://github.com/mrmlnc/fast-glob) - check out its documentation for [supported glob patterns](https://github.com/mrmlnc/fast-glob#pattern-syntax).
+- You should also be aware that all the arguments in the `import.meta.glob` must be **passed as literals**. You can NOT use variables or expressions in them.
## WebAssembly
diff --git a/docs/guide/index.md b/docs/guide/index.md
index ff0d3f21b90e65..338bd42a565aa3 100644
--- a/docs/guide/index.md
+++ b/docs/guide/index.md
@@ -38,7 +38,7 @@ The supported template presets are:
## Scaffolding Your First Vite Project
::: tip Compatibility Note
-Vite requires [Node.js](https://nodejs.org/en/) version >=12.2.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
+Vite requires [Node.js](https://nodejs.org/en/) version >=14.6.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
:::
With NPM:
@@ -113,7 +113,7 @@ Running `vite` starts the dev server using the current working directory as root
## Command Line Interface
-In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here is the default npm scripts in a scaffolded Vite project:
+In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here are the default npm scripts in a scaffolded Vite project:
```json5
diff --git a/docs/guide/ssr.md b/docs/guide/ssr.md
index d1fca329abd58d..1abd4874bca0e2 100644
--- a/docs/guide/ssr.md
+++ b/docs/guide/ssr.md
@@ -22,8 +22,8 @@ If you have questions, the community is usually helpful at [Vite Discord's #ssr
Vite provides built-in support for server-side rendering (SSR). The Vite playground contains example SSR setups for Vue 3 and React, which can be used as references for this guide:
-- [Vue 3](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-vue)
-- [React](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-react)
+- [Vue 3](https://github.com/vitejs/vite/tree/main/playground/ssr-vue)
+- [React](https://github.com/vitejs/vite/tree/main/playground/ssr-react)
## Source Structure
@@ -177,7 +177,7 @@ Then, in `server.js` we need to add some production specific logic by checking `
- Move the creation and all usage of the `vite` dev server behind dev-only conditional branches, then add static file serving middlewares to serve files from `dist/client`.
-Refer to the [Vue](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-vue) and [React](https://github.com/vitejs/vite/tree/main/packages/playground/ssr-react) demos for working setup.
+Refer to the [Vue](https://github.com/vitejs/vite/tree/main/playground/ssr-vue) and [React](https://github.com/vitejs/vite/tree/main/playground/ssr-react) demos for working setup.
## Generating Preload Directives
@@ -201,11 +201,11 @@ const html = await vueServerRenderer.renderToString(app, ctx)
// ctx.modules is now a Set of module IDs that were used during the render
```
-In the production branch of `server.js` we need to read and pass the manifest to the `render` function exported by `src/entry-server.js`. This would provide us with enough information to render preload directives for files used by async routes! See [demo source](https://github.com/vitejs/vite/blob/main/packages/playground/ssr-vue/src/entry-server.js) for full example.
+In the production branch of `server.js` we need to read and pass the manifest to the `render` function exported by `src/entry-server.js`. This would provide us with enough information to render preload directives for files used by async routes! See [demo source](https://github.com/vitejs/vite/blob/main/playground/ssr-vue/src/entry-server.js) for full example.
## Pre-Rendering / SSG
-If the routes and the data needed for certain routes are known ahead of time, we can pre-render these routes into static HTML using the same logic as production SSR. This can also be considered a form of Static-Site Generation (SSG). See [demo pre-render script](https://github.com/vitejs/vite/blob/main/packages/playground/ssr-vue/prerender.js) for working example.
+If the routes and the data needed for certain routes are known ahead of time, we can pre-render these routes into static HTML using the same logic as production SSR. This can also be considered a form of Static-Site Generation (SSG). See [demo pre-render script](https://github.com/vitejs/vite/blob/main/playground/ssr-vue/prerender.js) for working example.
## SSR Externals
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 89ca7698394246..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).
diff --git a/docs/plugins/index.md b/docs/plugins/index.md
index 6d81a060cf8883..0a8803ba2d3b9a 100644
--- a/docs/plugins/index.md
+++ b/docs/plugins/index.md
@@ -4,6 +4,8 @@
Vite aims to provide out-of-the-box support for common web development patterns. Before searching for a Vite or Compatible Rollup plugin, check out the [Features Guide](../guide/features.md). A lot of the cases where a plugin would be needed in a Rollup project are already covered in Vite.
:::
+Check out [Using Plugins](../guide/using-plugins) for information on how to use plugins.
+
## Official Plugins
### [@vitejs/plugin-vue](https://github.com/vitejs/vite/tree/main/packages/plugin-vue)
diff --git a/jest.config.ts b/jest.config.ts
index 11663af4e08107..719d67f39b8bce 100644
--- a/jest.config.ts
+++ b/jest.config.ts
@@ -3,22 +3,20 @@ import type { Config } from '@jest/types'
const config: Config.InitialOptions = {
preset: 'ts-jest',
- testMatch: process.env.VITE_TEST_BUILD
- ? ['**/playground/**/*.spec.[jt]s?(x)']
- : ['**/*.spec.[jt]s?(x)'],
+ testMatch: ['**/playground/**/*.spec.[jt]s?(x)'],
testTimeout: process.env.CI ? 50000 : 20000,
globalSetup: './scripts/jestGlobalSetup.cjs',
globalTeardown: './scripts/jestGlobalTeardown.cjs',
testEnvironment: './scripts/jestEnv.cjs',
setupFilesAfterEnv: ['./scripts/jestPerTestSetup.ts'],
- watchPathIgnorePatterns: ['/packages/temp'],
- modulePathIgnorePatterns: ['/packages/temp'],
+ watchPathIgnorePatterns: ['/playground-temp'],
+ modulePathIgnorePatterns: ['/playground-temp'],
moduleNameMapper: {
- testUtils: '/packages/playground/testUtils.ts'
+ testUtils: '/playground/testUtils.ts'
},
globals: {
'ts-jest': {
- tsconfig: './packages/playground/tsconfig.json'
+ tsconfig: './playground/tsconfig.json'
}
}
}
diff --git a/netlify.toml b/netlify.toml
index ba9d1c55f567c5..ba62bdbe4d6be1 100644
--- a/netlify.toml
+++ b/netlify.toml
@@ -3,4 +3,4 @@
NPM_FLAGS = "--version" # prevent Netlify npm install
[build]
publish = "docs/.vitepress/dist"
- command = "npx pnpm i --store=node_modules/.pnpm-store && npm run ci-docs"
\ No newline at end of file
+ command = "npx pnpm@6 i --store=node_modules/.pnpm-store --frozen-lockfile && npx pnpm@6 run ci-docs"
\ No newline at end of file
diff --git a/package.json b/package.json
index f6166c2985a30c..1ba4ca2cec68dc 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "vite-monorepo",
"private": true,
"engines": {
- "node": ">=12.2.0"
+ "node": ">=14.6.0"
},
"homepage": "https://vitejs.dev/",
"keywords": [
@@ -16,10 +16,11 @@
"preinstall": "npx only-allow pnpm",
"format": "prettier --write .",
"lint": "eslint packages/*/{src,types}/**",
- "test": "run-s test-serve test-build",
+ "test": "run-s test-unit test-serve test-build",
"test-serve": "jest",
- "debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest",
"test-build": "cross-env VITE_TEST_BUILD=1 jest",
+ "test-unit": "vitest run",
+ "debug-serve": "cross-env VITE_DEBUG_SERVE=1 node --inspect-brk ./node_modules/.bin/jest",
"debug-build": "cross-env VITE_TEST_BUILD=1 VITE_PRESERVE_BUILD_ARTIFACTS=1 node --inspect-brk ./node_modules/.bin/jest",
"docs": "vitepress dev docs",
"build-docs": "vitepress build docs",
@@ -34,41 +35,42 @@
"ci-docs": "run-s build-vite build-plugin-vue build-docs"
},
"devDependencies": {
- "@microsoft/api-extractor": "^7.19.5",
+ "@microsoft/api-extractor": "^7.23.1",
"@types/fs-extra": "^9.0.13",
- "@types/jest": "^27.4.1",
- "@types/node": "^16.11.26",
- "@types/prompts": "^2.0.14",
+ "@types/jest": "^27.5.0",
+ "@types/node": "^17.0.31",
+ "@types/prompts": "^2.4.0",
"@types/semver": "^7.3.9",
- "@typescript-eslint/eslint-plugin": "^5.16.0",
- "@typescript-eslint/parser": "^5.16.0",
+ "@typescript-eslint/eslint-plugin": "^5.22.0",
+ "@typescript-eslint/parser": "^5.22.0",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
- "esbuild": "^0.14.27",
- "eslint": "^8.12.0",
- "eslint-define-config": "^1.3.0",
+ "esbuild": "^0.14.38",
+ "eslint": "^8.15.0",
+ "eslint-define-config": "^1.4.0",
"eslint-plugin-node": "^11.1.0",
"execa": "^5.1.1",
- "fs-extra": "^10.0.1",
+ "fs-extra": "^10.1.0",
"jest": "^27.5.1",
- "lint-staged": "^12.3.7",
+ "lint-staged": "^12.4.1",
"minimist": "^1.2.6",
- "node-fetch": "^2.6.6",
+ "node-fetch": "^2.6.7",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
- "playwright-chromium": "^1.20.1",
- "prettier": "2.6.1",
+ "playwright-chromium": "^1.21.1",
+ "prettier": "2.6.2",
"prompts": "^2.4.2",
"rimraf": "^3.0.2",
- "rollup": "^2.59.0",
- "semver": "^7.3.5",
+ "rollup": "^2.72.1",
+ "semver": "^7.3.7",
"simple-git-hooks": "^2.7.0",
"sirv": "^2.0.2",
"ts-jest": "^27.1.4",
- "ts-node": "^10.4.0",
- "typescript": "~4.5.4",
+ "ts-node": "^10.7.0",
+ "typescript": "^4.6.4",
"vite": "workspace:*",
- "vitepress": "^0.22.3"
+ "vitepress": "^0.22.4",
+ "vitest": "^0.10.5"
},
"simple-git-hooks": {
"pre-commit": "pnpm exec lint-staged --concurrent false",
@@ -85,7 +87,7 @@
"eslint --ext .ts"
]
},
- "packageManager": "pnpm@6.32.3",
+ "packageManager": "pnpm@6.32.11",
"pnpm": {
"overrides": {
"vite": "workspace:*",
diff --git a/packages/create-vite/CHANGELOG.md b/packages/create-vite/CHANGELOG.md
index bf69fae7e535ad..d8759a4e269c97 100644
--- a/packages/create-vite/CHANGELOG.md
+++ b/packages/create-vite/CHANGELOG.md
@@ -1,3 +1,28 @@
+## 2.9.3 (2022-05-02)
+
+* chore(create-vite): update reference to volar vscode extension (#7994) ([2b6d8fe](https://github.com/vitejs/vite/commit/2b6d8fe)), closes [#7994](https://github.com/vitejs/vite/issues/7994)
+* feat(create-vite): scaffold directory with only .git (#7971) ([a5bdb9f](https://github.com/vitejs/vite/commit/a5bdb9f)), closes [#7971](https://github.com/vitejs/vite/issues/7971)
+
+
+
+## 2.9.2 (2022-04-19)
+
+* chore: remove useless code in preact template (#7789) ([e5729be](https://github.com/vitejs/vite/commit/e5729be)), closes [#7789](https://github.com/vitejs/vite/issues/7789)
+* fix(create-vite): bump `vue-tsc` to `0.34.7` (#7760) ([9a93233](https://github.com/vitejs/vite/commit/9a93233)), closes [#7760](https://github.com/vitejs/vite/issues/7760)
+* fix(create-vite): set skipLibCheck true (#7726) ([54e9cdd](https://github.com/vitejs/vite/commit/54e9cdd)), closes [#7726](https://github.com/vitejs/vite/issues/7726)
+
+
+
+## 2.9.1 (2022-04-13)
+
+* chore: fix term cases (#7553) ([c296130](https://github.com/vitejs/vite/commit/c296130)), closes [#7553](https://github.com/vitejs/vite/issues/7553)
+* chore: update @types/react version (#7655) ([eb57627](https://github.com/vitejs/vite/commit/eb57627)), closes [#7655](https://github.com/vitejs/vite/issues/7655)
+* chore: update vue template setup api doc url (#7628) ([4433df4](https://github.com/vitejs/vite/commit/4433df4)), closes [#7628](https://github.com/vitejs/vite/issues/7628)
+* chore(create-vite-app): upgrade react to 18 (#7597) ([8b21029](https://github.com/vitejs/vite/commit/8b21029)), closes [#7597](https://github.com/vitejs/vite/issues/7597)
+* chore(create-vite): add isolatedModules (#7697) ([8f28350](https://github.com/vitejs/vite/commit/8f28350)), closes [#7697](https://github.com/vitejs/vite/issues/7697)
+
+
+
## 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)
diff --git a/packages/create-vite/README.md b/packages/create-vite/README.md
index 79d5ae12d93597..e22c268ab99f9c 100644
--- a/packages/create-vite/README.md
+++ b/packages/create-vite/README.md
@@ -3,7 +3,7 @@
## Scaffolding Your First Vite Project
> **Compatibility Note:**
-> Vite requires [Node.js](https://nodejs.org/en/) version >=12.2.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
+> Vite requires [Node.js](https://nodejs.org/en/) version >=14.6.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
With NPM:
diff --git a/packages/create-vite/__tests__/cli.spec.ts b/packages/create-vite/__tests__/cli.spec.ts
index c52998172149e6..fbfb606f486885 100644
--- a/packages/create-vite/__tests__/cli.spec.ts
+++ b/packages/create-vite/__tests__/cli.spec.ts
@@ -3,6 +3,7 @@ import type { ExecaSyncReturnValue, SyncOptions } from 'execa'
import { commandSync } from 'execa'
import { mkdirpSync, readdirSync, remove, writeFileSync } from 'fs-extra'
import { join } from 'path'
+import { test, expect, beforeAll, afterEach } from 'vitest'
const CLI_PATH = join(__dirname, '..')
diff --git a/packages/create-vite/index.js b/packages/create-vite/index.js
index cc0a78639755bb..fceef9d9885a05 100755
--- a/packages/create-vite/index.js
+++ b/packages/create-vite/index.js
@@ -313,7 +313,8 @@ function copyDir(srcDir, destDir) {
}
function isEmpty(path) {
- return fs.readdirSync(path).length === 0
+ const files = fs.readdirSync(path)
+ return files.length === 0 || (files.length === 1 && files[0] === '.git')
}
function emptyDir(dir) {
diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json
index 72955697360477..38ffa81a2768ee 100644
--- a/packages/create-vite/package.json
+++ b/packages/create-vite/package.json
@@ -1,6 +1,6 @@
{
"name": "create-vite",
- "version": "2.9.0",
+ "version": "2.9.3",
"license": "MIT",
"author": "Evan You",
"bin": {
@@ -13,7 +13,7 @@
],
"main": "index.js",
"engines": {
- "node": ">=12.0.0"
+ "node": ">=14.6.0"
},
"repository": {
"type": "git",
diff --git a/packages/create-vite/template-lit-ts/package.json b/packages/create-vite/template-lit-ts/package.json
index 061def321a22e6..40b05d66af64f2 100644
--- a/packages/create-vite/template-lit-ts/package.json
+++ b/packages/create-vite/template-lit-ts/package.json
@@ -2,9 +2,9 @@
"name": "vite-lit-ts-starter",
"private": true,
"version": "0.0.0",
- "main": "dist/my-element.es.js",
+ "main": "dist/my-element.es.mjs",
"exports": {
- ".": "./dist/my-element.es.js"
+ ".": "./dist/my-element.es.mjs"
},
"types": "types/my-element.d.ts",
"files": [
@@ -16,10 +16,10 @@
"build": "tsc && vite build"
},
"dependencies": {
- "lit": "^2.0.2"
+ "lit": "^2.2.3"
},
"devDependencies": {
- "vite": "^2.9.0",
- "typescript": "^4.5.4"
+ "typescript": "^4.6.4",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-lit-ts/tsconfig.json b/packages/create-vite/template-lit-ts/tsconfig.json
index 03ecaf410c88be..91a731fd8619d4 100644
--- a/packages/create-vite/template-lit-ts/tsconfig.json
+++ b/packages/create-vite/template-lit-ts/tsconfig.json
@@ -11,10 +11,12 @@
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
+ "isolatedModules": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
- "useDefineForClassFields": false
+ "useDefineForClassFields": false,
+ "skipLibCheck": true
},
"include": ["src/**/*.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
diff --git a/packages/create-vite/template-lit/package.json b/packages/create-vite/template-lit/package.json
index 89f4fee41576c6..ca610090e22759 100644
--- a/packages/create-vite/template-lit/package.json
+++ b/packages/create-vite/template-lit/package.json
@@ -2,9 +2,9 @@
"name": "vite-lit-starter",
"private": true,
"version": "0.0.0",
- "main": "dist/my-element.es.js",
+ "main": "dist/my-element.es.mjs",
"exports": {
- ".": "./dist/my-element.es.js"
+ ".": "./dist/my-element.es.mjs"
},
"files": [
"dist"
@@ -14,9 +14,9 @@
"build": "vite build"
},
"dependencies": {
- "lit": "^2.0.2"
+ "lit": "^2.2.3"
},
"devDependencies": {
- "vite": "^2.9.0"
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-preact-ts/package.json b/packages/create-vite/template-preact-ts/package.json
index dfa6659650c5ae..dfff04ee49f099 100644
--- a/packages/create-vite/template-preact-ts/package.json
+++ b/packages/create-vite/template-preact-ts/package.json
@@ -8,11 +8,11 @@
"preview": "vite preview"
},
"dependencies": {
- "preact": "^10.5.15"
+ "preact": "^10.7.2"
},
"devDependencies": {
- "@preact/preset-vite": "^2.1.5",
- "typescript": "^4.5.4",
- "vite": "^2.9.0"
+ "@preact/preset-vite": "^2.2.0",
+ "typescript": "^4.6.4",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-preact-ts/tsconfig.json b/packages/create-vite/template-preact-ts/tsconfig.json
index fda60ae884247a..0a24dec18dd4f8 100644
--- a/packages/create-vite/template-preact-ts/tsconfig.json
+++ b/packages/create-vite/template-preact-ts/tsconfig.json
@@ -4,7 +4,7 @@
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
- "skipLibCheck": false,
+ "skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
diff --git a/packages/create-vite/template-preact/package.json b/packages/create-vite/template-preact/package.json
index 02528128f6442e..90cf6755ee8907 100644
--- a/packages/create-vite/template-preact/package.json
+++ b/packages/create-vite/template-preact/package.json
@@ -8,10 +8,10 @@
"preview": "vite preview"
},
"dependencies": {
- "preact": "^10.5.15"
+ "preact": "^10.7.2"
},
"devDependencies": {
- "@preact/preset-vite": "^2.1.5",
- "vite": "^2.9.0"
+ "@preact/preset-vite": "^2.2.0",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-preact/src/app.jsx b/packages/create-vite/template-preact/src/app.jsx
index 9d649444f686d9..64fe3eda94c933 100644
--- a/packages/create-vite/template-preact/src/app.jsx
+++ b/packages/create-vite/template-preact/src/app.jsx
@@ -1,6 +1,6 @@
import { Logo } from './logo'
-export function App(props) {
+export function App() {
return (
<>
diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json
index 00f99c8669d660..5a6ffff172f3ab 100644
--- a/packages/create-vite/template-react-ts/package.json
+++ b/packages/create-vite/template-react-ts/package.json
@@ -8,14 +8,14 @@
"preview": "vite preview"
},
"dependencies": {
- "react": "^17.0.2",
- "react-dom": "^17.0.2"
+ "react": "^18.1.0",
+ "react-dom": "^18.1.0"
},
"devDependencies": {
- "@types/react": "^17.0.33",
- "@types/react-dom": "^17.0.10",
- "@vitejs/plugin-react": "^1.0.7",
- "typescript": "^4.5.4",
- "vite": "^2.9.0"
+ "@types/react": "^18.0.9",
+ "@types/react-dom": "^18.0.3",
+ "@vitejs/plugin-react": "^1.3.2",
+ "typescript": "^4.6.4",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-react-ts/src/main.tsx b/packages/create-vite/template-react-ts/src/main.tsx
index 606a3cf44ec02b..4a1b15096e15b1 100644
--- a/packages/create-vite/template-react-ts/src/main.tsx
+++ b/packages/create-vite/template-react-ts/src/main.tsx
@@ -1,11 +1,10 @@
import React from 'react'
-import ReactDOM from 'react-dom'
-import './index.css'
+import ReactDOM from 'react-dom/client'
import App from './App'
+import './index.css'
-ReactDOM.render(
+ReactDOM.createRoot(document.getElementById('root')!).render(
- ,
- document.getElementById('root')
+
)
diff --git a/packages/create-vite/template-react-ts/tsconfig.json b/packages/create-vite/template-react-ts/tsconfig.json
index c8bdc64082aa26..3d0a51a86e2024 100644
--- a/packages/create-vite/template-react-ts/tsconfig.json
+++ b/packages/create-vite/template-react-ts/tsconfig.json
@@ -4,7 +4,7 @@
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
- "skipLibCheck": false,
+ "skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json
index f6a93540f0d3ee..92f2dee91fdc48 100644
--- a/packages/create-vite/template-react/package.json
+++ b/packages/create-vite/template-react/package.json
@@ -8,11 +8,13 @@
"preview": "vite preview"
},
"dependencies": {
- "react": "^17.0.2",
- "react-dom": "^17.0.2"
+ "react": "^18.1.0",
+ "react-dom": "^18.1.0"
},
"devDependencies": {
- "@vitejs/plugin-react": "^1.0.7",
- "vite": "^2.9.0"
+ "@types/react": "^18.0.9",
+ "@types/react-dom": "^18.0.3",
+ "@vitejs/plugin-react": "^1.3.2",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-react/src/main.jsx b/packages/create-vite/template-react/src/main.jsx
index 606a3cf44ec02b..9af0bb638e42c0 100644
--- a/packages/create-vite/template-react/src/main.jsx
+++ b/packages/create-vite/template-react/src/main.jsx
@@ -1,11 +1,10 @@
import React from 'react'
-import ReactDOM from 'react-dom'
-import './index.css'
+import ReactDOM from 'react-dom/client'
import App from './App'
+import './index.css'
-ReactDOM.render(
+ReactDOM.createRoot(document.getElementById('root')).render(
- ,
- document.getElementById('root')
+
)
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 32e080146e0b6e..94cb978899ed0b 100644
--- a/packages/create-vite/template-svelte-ts/package.json
+++ b/packages/create-vite/template-svelte-ts/package.json
@@ -10,13 +10,13 @@
"check": "svelte-check --tsconfig ./tsconfig.json"
},
"devDependencies": {
- "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
+ "@sveltejs/vite-plugin-svelte": "^1.0.0-next.43",
"@tsconfig/svelte": "^2.0.1",
- "svelte": "^3.44.0",
- "svelte-check": "^2.2.7",
- "svelte-preprocess": "^4.9.8",
- "tslib": "^2.3.1",
- "typescript": "^4.5.4",
- "vite": "^2.9.0"
+ "svelte": "^3.48.0",
+ "svelte-check": "^2.7.0",
+ "svelte-preprocess": "^4.10.6",
+ "tslib": "^2.4.0",
+ "typescript": "^4.6.4",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-svelte-ts/tsconfig.json b/packages/create-vite/template-svelte-ts/tsconfig.json
index 4d6c04cf0ab13b..96bfd81aaf1203 100644
--- a/packages/create-vite/template-svelte-ts/tsconfig.json
+++ b/packages/create-vite/template-svelte-ts/tsconfig.json
@@ -13,7 +13,8 @@
* of JS in `.svelte` files.
*/
"allowJs": true,
- "checkJs": true
+ "checkJs": true,
+ "isolatedModules": true
},
"include": ["src/**/*.d.ts", "src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
"references": [{ "path": "./tsconfig.node.json" }]
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 da049c170731b9..7153b3389662e0 100644
--- a/packages/create-vite/template-svelte/package.json
+++ b/packages/create-vite/template-svelte/package.json
@@ -9,8 +9,8 @@
"preview": "vite preview"
},
"devDependencies": {
- "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30",
- "svelte": "^3.44.0",
- "vite": "^2.9.0"
+ "@sveltejs/vite-plugin-svelte": "^1.0.0-next.43",
+ "svelte": "^3.48.0",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-vanilla-ts/package.json b/packages/create-vite/template-vanilla-ts/package.json
index 8dd7a0bb800909..8dd9deee768e4c 100644
--- a/packages/create-vite/template-vanilla-ts/package.json
+++ b/packages/create-vite/template-vanilla-ts/package.json
@@ -8,7 +8,7 @@
"preview": "vite preview"
},
"devDependencies": {
- "typescript": "^4.5.4",
- "vite": "^2.9.0"
+ "typescript": "^4.6.4",
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-vanilla-ts/tsconfig.json b/packages/create-vite/template-vanilla-ts/tsconfig.json
index 1885c8f9b00106..fbd022532d3096 100644
--- a/packages/create-vite/template-vanilla-ts/tsconfig.json
+++ b/packages/create-vite/template-vanilla-ts/tsconfig.json
@@ -8,11 +8,13 @@
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
+ "isolatedModules": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
- "noImplicitReturns": true
+ "noImplicitReturns": true,
+ "skipLibCheck": true
},
"include": ["src"]
}
diff --git a/packages/create-vite/template-vanilla/package.json b/packages/create-vite/template-vanilla/package.json
index ff318e00f14fd1..b1ce70c284540f 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.9.0"
+ "vite": "^2.9.8"
}
}
diff --git a/packages/create-vite/template-vue-ts/.vscode/extensions.json b/packages/create-vite/template-vue-ts/.vscode/extensions.json
index 3dc5b08bcdc96b..a7cea0b0678120 100644
--- a/packages/create-vite/template-vue-ts/.vscode/extensions.json
+++ b/packages/create-vite/template-vue-ts/.vscode/extensions.json
@@ -1,3 +1,3 @@
{
- "recommendations": ["johnsoncodehk.volar"]
+ "recommendations": ["Vue.volar"]
}
diff --git a/packages/create-vite/template-vue-ts/README.md b/packages/create-vite/template-vue-ts/README.md
index b53dcfb1a715e6..30b15e215a24b7 100644
--- a/packages/create-vite/template-vue-ts/README.md
+++ b/packages/create-vite/template-vue-ts/README.md
@@ -1,16 +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 `
diff --git a/packages/create-vite/template-vue-ts/src/components/HelloWorld.vue b/packages/create-vite/template-vue-ts/src/components/HelloWorld.vue
index 2d61249ac32f9c..38dae70739a15a 100644
--- a/packages/create-vite/template-vue-ts/src/components/HelloWorld.vue
+++ b/packages/create-vite/template-vue-ts/src/components/HelloWorld.vue
@@ -11,7 +11,7 @@ const count = ref(0)
diff --git a/packages/playground/lib/src/main.js b/packages/playground/lib/src/main.js
deleted file mode 100644
index 2422edf5829a0e..00000000000000
--- a/packages/playground/lib/src/main.js
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function myLib(sel) {
- document.querySelector(sel).textContent = 'It works'
-}
diff --git a/packages/playground/optimize-missing-deps/missing-dep/index.js b/packages/playground/optimize-missing-deps/missing-dep/index.js
deleted file mode 100644
index f5d61c545d080a..00000000000000
--- a/packages/playground/optimize-missing-deps/missing-dep/index.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import { name } from 'multi-entry-dep'
-
-export function sayName() {
- return name
-}
diff --git a/packages/playground/worker/emit-chunk-dynamic-import-worker.js b/packages/playground/worker/emit-chunk-dynamic-import-worker.js
deleted file mode 100644
index f96e0b15d26497..00000000000000
--- a/packages/playground/worker/emit-chunk-dynamic-import-worker.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import('./modules/module').then((module) => {
- self.postMessage(module.default + import.meta.env.BASE_URL)
-})
diff --git a/packages/playground/worker/module-and-worker.js b/packages/playground/worker/module-and-worker.js
deleted file mode 100644
index 659e556f08e4a6..00000000000000
--- a/packages/playground/worker/module-and-worker.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import constant from './modules/module'
-
-self.postMessage(constant)
-
-export const module = 'module and worker'
diff --git a/packages/playground/worker/sub-worker.js b/packages/playground/worker/sub-worker.js
deleted file mode 100644
index eff49dfbb46ba6..00000000000000
--- a/packages/playground/worker/sub-worker.js
+++ /dev/null
@@ -1,5 +0,0 @@
-self.onmessage = (event) => {
- if (event.data === 'ping') {
- self.postMessage(`pong ${import.meta.url}`)
- }
-}
diff --git a/packages/playground/worker/url-shared-worker.js b/packages/playground/worker/url-shared-worker.js
deleted file mode 100644
index 3535d5c277ec84..00000000000000
--- a/packages/playground/worker/url-shared-worker.js
+++ /dev/null
@@ -1,6 +0,0 @@
-import constant from './modules/module'
-
-self.onconnect = (event) => {
- const port = event.ports[0]
- port.postMessage(constant)
-}
diff --git a/packages/playground/worker/url-worker.js b/packages/playground/worker/url-worker.js
deleted file mode 100644
index c25cbefdff89ec..00000000000000
--- a/packages/playground/worker/url-worker.js
+++ /dev/null
@@ -1 +0,0 @@
-self.postMessage('A string' + import.meta.env.BASE_URL + import.meta.url)
diff --git a/packages/playground/worker/worker-nested-worker.js b/packages/playground/worker/worker-nested-worker.js
deleted file mode 100644
index 6d4d1e4969005f..00000000000000
--- a/packages/playground/worker/worker-nested-worker.js
+++ /dev/null
@@ -1,13 +0,0 @@
-import SubWorker from './sub-worker?worker'
-
-const subWorker = new SubWorker()
-
-self.onmessage = (event) => {
- if (event.data === 'ping') {
- subWorker.postMessage('ping')
- }
-}
-
-subWorker.onmessage = (event) => {
- self.postMessage(event.data)
-}
diff --git a/packages/plugin-legacy/CHANGELOG.md b/packages/plugin-legacy/CHANGELOG.md
index ced87d2efd665c..035460b5816cb5 100644
--- a/packages/plugin-legacy/CHANGELOG.md
+++ b/packages/plugin-legacy/CHANGELOG.md
@@ -1,3 +1,19 @@
+## 1.8.2 (2022-05-02)
+
+* chore(deps): update all non-major dependencies (#7780) ([eba9d05](https://github.com/vitejs/vite/commit/eba9d05)), closes [#7780](https://github.com/vitejs/vite/issues/7780)
+* chore(deps): update all non-major dependencies (#7847) ([e29d1d9](https://github.com/vitejs/vite/commit/e29d1d9)), closes [#7847](https://github.com/vitejs/vite/issues/7847)
+* chore(deps): update all non-major dependencies (#7949) ([b877d30](https://github.com/vitejs/vite/commit/b877d30)), closes [#7949](https://github.com/vitejs/vite/issues/7949)
+* refactor(legacy): remove unneeded dynamic import var init code (#7759) ([12a4e7d](https://github.com/vitejs/vite/commit/12a4e7d)), closes [#7759](https://github.com/vitejs/vite/issues/7759)
+
+
+
+## 1.8.1 (2022-04-13)
+
+* fix(deps): update all non-major dependencies (#7668) ([485263c](https://github.com/vitejs/vite/commit/485263c)), closes [#7668](https://github.com/vitejs/vite/issues/7668)
+* docs(legacy): note works in build only (#7596) ([f26b14a](https://github.com/vitejs/vite/commit/f26b14a)), closes [#7596](https://github.com/vitejs/vite/issues/7596)
+
+
+
## 1.8.0 (2022-03-30)
* fix(deps): update all non-major dependencies (#6782) ([e38be3e](https://github.com/vitejs/vite/commit/e38be3e)), closes [#6782](https://github.com/vitejs/vite/issues/6782)
diff --git a/packages/plugin-legacy/README.md b/packages/plugin-legacy/README.md
index ec7e630c87755a..fc4167f4f1010f 100644
--- a/packages/plugin-legacy/README.md
+++ b/packages/plugin-legacy/README.md
@@ -1,8 +1,6 @@
# @vitejs/plugin-legacy [![npm](https://img.shields.io/npm/v/@vitejs/plugin-legacy.svg)](https://npmjs.com/package/@vitejs/plugin-legacy)
-**Note: this plugin requires `vite@^2.0.0`**.
-
-Vite's default browser support baseline is [Native ESM](https://caniuse.com/es6-module). This plugin provides support for legacy browsers that do not support native ESM.
+Vite's default browser support baseline is [Native ESM](https://caniuse.com/es6-module). This plugin provides support for legacy browsers that do not support native ESM when building for production.
By default, this plugin will:
@@ -29,22 +27,6 @@ export default {
}
```
-When targeting IE11, you also need `regenerator-runtime`:
-
-```js
-// vite.config.js
-import legacy from '@vitejs/plugin-legacy'
-
-export default {
- plugins: [
- legacy({
- targets: ['ie >= 11'],
- additionalLegacyPolyfills: ['regenerator-runtime/runtime']
- })
- ]
-}
-```
-
## Options
### `targets`
@@ -165,7 +147,6 @@ The legacy plugin requires inline scripts for [Safari 10.1 `nomodule` fix](https
- `sha256-MS6/3FCg4WjP9gwgaBGwLpRCY6fZBgwmhVCdrPrNf3E=`
- `sha256-tQjf8gvb2ROOMapIxFvFAYBeUJ0v1HCbOcSmDNXGtDo=`
-- `sha256-xYj09txJ9OsgySe5ommpqul6FiaJZRrwe3KTD7wbV6w=`
- `sha256-4m6wOIrq/wFDmi9Xh3mFM2mwI4ik9n3TMgHk6xDtLxk=`
- `sha256-uS7/g9fhQwNZS1f/MqYqqKv8y9hCu36IfX9XZB5L7YY=`
diff --git a/packages/plugin-legacy/index.js b/packages/plugin-legacy/index.js
index 41f7157ebfc533..2f1b1991c31c31 100644
--- a/packages/plugin-legacy/index.js
+++ b/packages/plugin-legacy/index.js
@@ -20,7 +20,6 @@ const legacyEntryId = 'vite-legacy-entry'
const systemJSInlineCode = `System.import(document.getElementById('${legacyEntryId}').getAttribute('data-src'))`
const detectDynamicImportVarName = '__vite_is_dynamic_import_support'
-const detectDynamicImportVarInitCode = `var ${detectDynamicImportVarName}=false;`
const detectDynamicImportCode = `try{import("_").catch(()=>1);}catch(e){}window.${detectDynamicImportVarName}=true;`
const dynamicFallbackInlineCode = `!function(){if(window.${detectDynamicImportVarName})return;console.warn("vite: loading legacy build because dynamic import is unsupported, syntax error above should be ignored");var e=document.getElementById("${legacyPolyfillId}"),n=document.createElement("script");n.src=e.src,n.onload=function(){${systemJSInlineCode}},document.body.appendChild(n)}();`
@@ -437,12 +436,6 @@ function viteLegacyPlugin(options = {}) {
// 5. inject dynamic import fallback entry
if (genDynamicFallback && legacyPolyfillFilename && legacyEntryFilename) {
- tags.push({
- tag: 'script',
- attrs: { type: 'module' },
- children: detectDynamicImportVarInitCode,
- injectTo: 'head'
- })
tags.push({
tag: 'script',
attrs: { type: 'module' },
@@ -714,7 +707,6 @@ viteLegacyPlugin.default = viteLegacyPlugin
viteLegacyPlugin.cspHashes = [
createHash('sha256').update(safari10NoModuleFix).digest('base64'),
createHash('sha256').update(systemJSInlineCode).digest('base64'),
- createHash('sha256').update(detectDynamicImportVarInitCode).digest('base64'),
createHash('sha256').update(detectDynamicImportCode).digest('base64'),
createHash('sha256').update(dynamicFallbackInlineCode).digest('base64')
]
diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json
index aa8c478e4dae18..296c994165747b 100644
--- a/packages/plugin-legacy/package.json
+++ b/packages/plugin-legacy/package.json
@@ -1,6 +1,6 @@
{
"name": "@vitejs/plugin-legacy",
- "version": "1.8.0",
+ "version": "1.8.2",
"license": "MIT",
"author": "Evan You",
"files": [
@@ -10,7 +10,7 @@
"main": "index.js",
"types": "index.d.ts",
"engines": {
- "node": ">=12.0.0"
+ "node": ">=14.6.0"
},
"repository": {
"type": "git",
@@ -22,8 +22,8 @@
},
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme",
"dependencies": {
- "@babel/standalone": "^7.17.8",
- "core-js": "^3.21.1",
+ "@babel/standalone": "^7.17.11",
+ "core-js": "^3.22.4",
"magic-string": "^0.26.1",
"regenerator-runtime": "^0.13.9",
"systemjs": "^6.12.1"
diff --git a/packages/plugin-react/CHANGELOG.md b/packages/plugin-react/CHANGELOG.md
index c05c0989d6beb4..01dfee3feb7ffb 100644
--- a/packages/plugin-react/CHANGELOG.md
+++ b/packages/plugin-react/CHANGELOG.md
@@ -1,3 +1,19 @@
+## 1.3.2 (2022-05-02)
+
+* fix(plugin-react): React is not defined when component name is lowercase (#6838) ([bf40e5c](https://github.com/vitejs/vite/commit/bf40e5c)), closes [#6838](https://github.com/vitejs/vite/issues/6838)
+* chore(deps): update all non-major dependencies (#7780) ([eba9d05](https://github.com/vitejs/vite/commit/eba9d05)), closes [#7780](https://github.com/vitejs/vite/issues/7780)
+* chore(deps): update all non-major dependencies (#7949) ([b877d30](https://github.com/vitejs/vite/commit/b877d30)), closes [#7949](https://github.com/vitejs/vite/issues/7949)
+
+
+
+## 1.3.1 (2022-04-13)
+
+* fix(deps): update all non-major dependencies (#7668) ([485263c](https://github.com/vitejs/vite/commit/485263c)), closes [#7668](https://github.com/vitejs/vite/issues/7668)
+* chore: fix term cases (#7553) ([c296130](https://github.com/vitejs/vite/commit/c296130)), closes [#7553](https://github.com/vitejs/vite/issues/7553)
+* chore(deps): update all non-major dependencies (#7603) ([fc51a15](https://github.com/vitejs/vite/commit/fc51a15)), closes [#7603](https://github.com/vitejs/vite/issues/7603)
+
+
+
## 1.3.0 (2022-03-30)
* feat(plugin-react): adding jsxPure option (#7088) ([d451435](https://github.com/vitejs/vite/commit/d451435)), closes [#7088](https://github.com/vitejs/vite/issues/7088)
diff --git a/packages/plugin-react/README.md b/packages/plugin-react/README.md
index 588f947ec8b08c..e8d27d0e57242b 100644
--- a/packages/plugin-react/README.md
+++ b/packages/plugin-react/README.md
@@ -75,7 +75,7 @@ react({
})
```
-This option does not enable _code transformation_. That is handled by ESBuild.
+This option does not enable _code transformation_. That is handled by esbuild.
**Note:** TypeScript syntax is handled automatically.
diff --git a/packages/plugin-react/package.json b/packages/plugin-react/package.json
index 8313fc5a81d648..813db5ecf23aed 100644
--- a/packages/plugin-react/package.json
+++ b/packages/plugin-react/package.json
@@ -1,6 +1,6 @@
{
"name": "@vitejs/plugin-react",
- "version": "1.3.0",
+ "version": "1.3.2",
"license": "MIT",
"author": "Evan You",
"contributors": [
@@ -21,7 +21,7 @@
"prepublishOnly": "(cd ../vite && npm run build) && npm run build"
},
"engines": {
- "node": ">=12.0.0"
+ "node": ">=14.6.0"
},
"repository": {
"type": "git",
@@ -33,13 +33,13 @@
},
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-react#readme",
"dependencies": {
- "@babel/core": "^7.17.8",
+ "@babel/core": "^7.17.10",
"@babel/plugin-transform-react-jsx": "^7.17.3",
"@babel/plugin-transform-react-jsx-development": "^7.16.7",
"@babel/plugin-transform-react-jsx-self": "^7.16.7",
"@babel/plugin-transform-react-jsx-source": "^7.16.7",
- "@rollup/pluginutils": "^4.2.0",
- "react-refresh": "^0.11.0",
+ "@rollup/pluginutils": "^4.2.1",
+ "react-refresh": "^0.13.0",
"resolve": "^1.22.0"
}
}
diff --git a/packages/plugin-react/src/fast-refresh.ts b/packages/plugin-react/src/fast-refresh.ts
index 70562bbbdfc5b7..4672e26f6264e3 100644
--- a/packages/plugin-react/src/fast-refresh.ts
+++ b/packages/plugin-react/src/fast-refresh.ts
@@ -1,10 +1,15 @@
import type { types as t } from '@babel/core'
import fs from 'fs'
+import path from 'path'
export const runtimePublicPath = '/@react-refresh'
-const runtimeFilePath = require.resolve(
- 'react-refresh/cjs/react-refresh-runtime.development.js'
+const reactRefreshDir = path.dirname(
+ require.resolve('react-refresh/package.json')
+)
+const runtimeFilePath = path.join(
+ reactRefreshDir,
+ 'cjs/react-refresh-runtime.development.js'
)
export const runtimeCode = `
diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts
index 76f6c6c2a799f3..4ca3e0d371f6c9 100644
--- a/packages/plugin-react/src/index.ts
+++ b/packages/plugin-react/src/index.ts
@@ -38,15 +38,10 @@ export interface Options {
* @default true
*/
jsxPure?: boolean
-
/**
* Babel configuration applied in both dev and prod.
*/
babel?: BabelOptions
- /**
- * @deprecated Use `babel.parserOpts.plugins` instead
- */
- parserPlugins?: ParserOptions['plugins']
}
export type BabelOptions = Omit<
@@ -104,7 +99,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
babelOptions.presets ||= []
babelOptions.overrides ||= []
babelOptions.parserOpts ||= {} as any
- babelOptions.parserOpts.plugins ||= opts.parserPlugins || []
+ babelOptions.parserOpts.plugins ||= []
// Support patterns like:
// - import * as React from 'react';
@@ -176,7 +171,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
if (isReactModule && filter(id)) {
useFastRefresh = true
plugins.push([
- await loadPlugin('react-refresh/babel.js'),
+ await loadPlugin('react-refresh/babel'),
{ skipEnvCheck: true }
])
}
diff --git a/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts
index 59d6661bedd11b..391007f68c1329 100644
--- a/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts
+++ b/packages/plugin-react/src/jsx-runtime/babel-restore-jsx.spec.ts
@@ -1,5 +1,6 @@
import babelRestoreJSX from './babel-restore-jsx'
import * as babel from '@babel/core'
+import { describe, it, expect } from 'vitest'
function jsx(code: string) {
return babel.transform(code, {
diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts
new file mode 100644
index 00000000000000..4f6a34ee60d915
--- /dev/null
+++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.spec.ts
@@ -0,0 +1,56 @@
+import { restoreJSX } from './restore-jsx'
+import * as babel from '@babel/core'
+import { describe, it, expect } from 'vitest'
+
+async function jsx(sourceCode: string) {
+ const [ast] = await restoreJSX(babel, sourceCode, 'test.js')
+ if (ast == null) {
+ return ast
+ }
+ const { code } = await babel.transformFromAstAsync(ast, null, {
+ configFile: false
+ })
+ return code
+}
+// jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+// React__default.createElement(Foo)`)
+// Tests adapted from: https://github.com/flying-sheep/babel-plugin-transform-react-createelement-to-jsx/blob/63137b6/test/index.js
+describe('restore-jsx', () => {
+ it('should trans to ', async () => {
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement(foo)`)
+ ).toBeNull()
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement("h1")`)
+ ).toMatch(`;`)
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement(Foo)`)
+ ).toMatch(`;`)
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement(Foo.Bar)`)
+ ).toMatch(`;`)
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement(Foo.Bar.Baz)`)
+ ).toMatch(`;`)
+ })
+
+ it('should handle props', async () => {
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement(foo, {hi: there})`)
+ ).toBeNull()
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement("h1", {hi: there})`)
+ ).toMatch(`;`)
+ expect(
+ await jsx(`import React__default, { PureComponent, Component, forwardRef, memo, createElement } from 'react';
+ React__default.createElement(Foo, {hi: there})`)
+ ).toMatch(`;`)
+ })
+})
diff --git a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts
index 268153f4ba5d45..dbc2218d2343ff 100644
--- a/packages/plugin-react/src/jsx-runtime/restore-jsx.ts
+++ b/packages/plugin-react/src/jsx-runtime/restore-jsx.ts
@@ -20,32 +20,42 @@ export async function restoreJSX(
}
const [reactAlias, isCommonJS] = parseReactAlias(code)
+
if (!reactAlias) {
return jsxNotFound
}
- const reactJsxRE = new RegExp(
- '\\b' + reactAlias + '\\.(createElement|Fragment)\\b',
- 'g'
- )
-
let hasCompiledJsx = false
- code = code.replace(reactJsxRE, (_, prop) => {
- hasCompiledJsx = true
- // Replace with "React" so JSX can be reverse compiled.
- return 'React.' + prop
- })
+
+ const fragmentPattern = `\\b${reactAlias}\\.Fragment\\b`
+ const createElementPattern = `\\b${reactAlias}\\.createElement\\(\\s*([A-Z"'][\\w$.]*["']?)`
+
+ // Replace the alias with "React" so JSX can be reverse compiled.
+ code = code
+ .replace(new RegExp(fragmentPattern, 'g'), () => {
+ hasCompiledJsx = true
+ return 'React.Fragment'
+ })
+ .replace(new RegExp(createElementPattern, 'g'), (original, component) => {
+ if (/^[a-z][\w$]*$/.test(component)) {
+ // Take care not to replace the alias for `createElement` calls whose
+ // component is a lowercased variable, since the `restoreJSX` Babel
+ // plugin leaves them untouched.
+ return original
+ }
+ hasCompiledJsx = true
+ return (
+ 'React.createElement(' +
+ // Assume `Fragment` is equivalent to `React.Fragment` so modules
+ // that use `import {Fragment} from 'react'` are reverse compiled.
+ (component === 'Fragment' ? 'React.Fragment' : component)
+ )
+ })
if (!hasCompiledJsx) {
return jsxNotFound
}
- // Support modules that use `import {Fragment} from 'react'`
- code = code.replace(
- /createElement\(Fragment,/g,
- 'createElement(React.Fragment,'
- )
-
babelRestoreJSX ||= import('./babel-restore-jsx')
const result = await babel.transformAsync(code, {
diff --git a/packages/plugin-vue-jsx/CHANGELOG.md b/packages/plugin-vue-jsx/CHANGELOG.md
index 3a1b9e681b45ea..94effd95f316b6 100644
--- a/packages/plugin-vue-jsx/CHANGELOG.md
+++ b/packages/plugin-vue-jsx/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 1.3.10 (2022-04-13)
+
+* fix(deps): update all non-major dependencies (#7668) ([485263c](https://github.com/vitejs/vite/commit/485263c)), closes [#7668](https://github.com/vitejs/vite/issues/7668)
+
+
+
## 1.3.9 (2022-03-30)
* fix(deps): update all non-major dependencies (#7392) ([b63fc3b](https://github.com/vitejs/vite/commit/b63fc3b)), closes [#7392](https://github.com/vitejs/vite/issues/7392)
diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js
index 248270765d19a1..929f4fb44cd434 100644
--- a/packages/plugin-vue-jsx/index.js
+++ b/packages/plugin-vue-jsx/index.js
@@ -48,12 +48,6 @@ function vueJsxPlugin(options = {}) {
name: 'vite:vue-jsx',
config(config) {
- const optionsApi = config.define
- ? config.define.__VUE_OPTIONS_API__
- : undefined
- const devTools = config.define
- ? config.define.__VUE_PROD_DEVTOOLS__
- : undefined
return {
// only apply esbuild to ts files
// since we are handling jsx and tsx now
@@ -61,8 +55,8 @@ function vueJsxPlugin(options = {}) {
include: /\.ts$/
},
define: {
- __VUE_OPTIONS_API__: optionsApi != null ? optionsApi : true,
- __VUE_PROD_DEVTOOLS__: devTools != null ? devTools : false
+ __VUE_OPTIONS_API__: config.define?.__VUE_OPTIONS_API__ ?? true,
+ __VUE_PROD_DEVTOOLS__: config.define?.__VUE_PROD_DEVTOOLS__ ?? false
}
}
},
diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json
index c6a352eccc99a0..91ef19c2049850 100644
--- a/packages/plugin-vue-jsx/package.json
+++ b/packages/plugin-vue-jsx/package.json
@@ -1,6 +1,6 @@
{
"name": "@vitejs/plugin-vue-jsx",
- "version": "1.3.9",
+ "version": "1.3.10",
"license": "MIT",
"author": "Evan You",
"files": [
@@ -10,7 +10,7 @@
"main": "index.js",
"types": "index.d.ts",
"engines": {
- "node": ">=12.0.0"
+ "node": ">=14.6.0"
},
"repository": {
"type": "git",
@@ -22,10 +22,10 @@
},
"homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-vue-jsx#readme",
"dependencies": {
- "@babel/core": "^7.17.8",
+ "@babel/core": "^7.17.10",
"@babel/plugin-syntax-import-meta": "^7.10.4",
"@babel/plugin-transform-typescript": "^7.16.8",
- "@rollup/pluginutils": "^4.2.0",
+ "@rollup/pluginutils": "^4.2.1",
"@vue/babel-plugin-jsx": "^1.1.1",
"hash-sum": "^2.0.0"
}
diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md
index 135daffbfaaa67..4990d5fc10bd50 100644
--- a/packages/plugin-vue/CHANGELOG.md
+++ b/packages/plugin-vue/CHANGELOG.md
@@ -1,3 +1,11 @@
+## 2.3.2 (2022-05-04)
+
+* feat: import ts with .js in vue (#7998) ([9974094](https://github.com/vitejs/vite/commit/9974094)), closes [#7998](https://github.com/vitejs/vite/issues/7998)
+* refactor(plugin-vue): remove querystring import (#7997) ([f3d15f1](https://github.com/vitejs/vite/commit/f3d15f1)), closes [#7997](https://github.com/vitejs/vite/issues/7997)
+* chore(deps): update all non-major dependencies (#7780) ([eba9d05](https://github.com/vitejs/vite/commit/eba9d05)), closes [#7780](https://github.com/vitejs/vite/issues/7780)
+
+
+
## 2.3.1 (2022-03-30)
* chore(plugin-vue): revert #7527, lower vite peer dep ([447bbeb](https://github.com/vitejs/vite/commit/447bbeb)), closes [#7527](https://github.com/vitejs/vite/issues/7527)
diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json
index 39b3bc87a8b1df..9124f4f97bffc1 100644
--- a/packages/plugin-vue/package.json
+++ b/packages/plugin-vue/package.json
@@ -1,6 +1,6 @@
{
"name": "@vitejs/plugin-vue",
- "version": "2.3.1",
+ "version": "2.3.2",
"license": "MIT",
"author": "Evan You",
"files": [
@@ -19,7 +19,7 @@
"prepublishOnly": "(cd ../vite && npm run build) && npm run build"
},
"engines": {
- "node": ">=12.0.0"
+ "node": ">=14.6.0"
},
"repository": {
"type": "git",
@@ -35,13 +35,13 @@
"vue": "^3.2.25"
},
"devDependencies": {
- "@rollup/pluginutils": "^4.2.0",
+ "@rollup/pluginutils": "^4.2.1",
"@types/hash-sum": "^1.0.0",
"debug": "^4.3.4",
"hash-sum": "^2.0.0",
- "rollup": "^2.59.0",
+ "rollup": "^2.72.1",
"slash": "^4.0.0",
"source-map": "^0.6.1",
- "vue": "^3.2.31"
+ "vue": "^3.2.33"
}
}
diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts
index 44b1de74721efd..1b24856be1ecab 100644
--- a/packages/plugin-vue/src/main.ts
+++ b/packages/plugin-vue/src/main.ts
@@ -1,4 +1,3 @@
-import qs from 'querystring'
import path from 'path'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { ResolvedOptions } from '.'
@@ -212,6 +211,11 @@ export async function transformMain(
code: resolvedCode,
map: resolvedMap || {
mappings: ''
+ },
+ meta: {
+ vite: {
+ lang: descriptor.script?.lang || descriptor.scriptSetup?.lang || 'js'
+ }
}
}
}
@@ -426,8 +430,8 @@ function attrsToQuery(
for (const name in attrs) {
const value = attrs[name]
if (!ignoreList.includes(name)) {
- query += `&${qs.escape(name)}${
- value ? `=${qs.escape(String(value))}` : ``
+ query += `&${encodeURIComponent(name)}${
+ value ? `=${encodeURIComponent(value)}` : ``
}`
}
}
diff --git a/packages/plugin-vue/src/template.ts b/packages/plugin-vue/src/template.ts
index 72e9588967556e..c7eed9015d6339 100644
--- a/packages/plugin-vue/src/template.ts
+++ b/packages/plugin-vue/src/template.ts
@@ -139,7 +139,7 @@ export function resolveTemplateCompilerOptions(
tags: transformAssetUrls as any
}
} else {
- transformAssetUrls = { ...transformAssetUrls, ...assetUrlOptions }
+ transformAssetUrls = { ...assetUrlOptions, ...transformAssetUrls }
}
} else {
transformAssetUrls = assetUrlOptions
diff --git a/packages/plugin-vue/src/utils/query.ts b/packages/plugin-vue/src/utils/query.ts
index d41cb1be2cf536..060b5f28987bfa 100644
--- a/packages/plugin-vue/src/utils/query.ts
+++ b/packages/plugin-vue/src/utils/query.ts
@@ -1,5 +1,3 @@
-import qs from 'querystring'
-
export interface VueQuery {
vue?: boolean
src?: string
@@ -14,7 +12,7 @@ export function parseVueRequest(id: string): {
query: VueQuery
} {
const [filename, rawQuery] = id.split(`?`, 2)
- const query = qs.parse(rawQuery) as VueQuery
+ const query = Object.fromEntries(new URLSearchParams(rawQuery)) as VueQuery
if (query.vue != null) {
query.vue = true
}
diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md
index 4037de1a2c0d5c..3c967f289c1f34 100644
--- a/packages/vite/CHANGELOG.md
+++ b/packages/vite/CHANGELOG.md
@@ -1,3 +1,112 @@
+## 2.9.8 (2022-05-04)
+
+* fix: inline js and css paths for virtual html (#7993) ([d49e3fb](https://github.com/vitejs/vite/commit/d49e3fb)), closes [#7993](https://github.com/vitejs/vite/issues/7993)
+* fix: only handle merge ssr.noExternal (#8003) ([642d65b](https://github.com/vitejs/vite/commit/642d65b)), closes [#8003](https://github.com/vitejs/vite/issues/8003)
+* fix: optimized processing folder renaming in win (fix #7939) (#8019) ([e5fe1c6](https://github.com/vitejs/vite/commit/e5fe1c6)), closes [#7939](https://github.com/vitejs/vite/issues/7939) [#8019](https://github.com/vitejs/vite/issues/8019)
+* fix(css): do not clean id when passing to postcss (fix #7822) (#7827) ([72f17f8](https://github.com/vitejs/vite/commit/72f17f8)), closes [#7822](https://github.com/vitejs/vite/issues/7822) [#7827](https://github.com/vitejs/vite/issues/7827)
+* fix(css): var in image-set (#7921) ([e96b908](https://github.com/vitejs/vite/commit/e96b908)), closes [#7921](https://github.com/vitejs/vite/issues/7921)
+* fix(ssr): allow ssrTransform to parse hashbang (#8005) ([6420ba0](https://github.com/vitejs/vite/commit/6420ba0)), closes [#8005](https://github.com/vitejs/vite/issues/8005)
+* feat: import ts with .js in vue (#7998) ([9974094](https://github.com/vitejs/vite/commit/9974094)), closes [#7998](https://github.com/vitejs/vite/issues/7998)
+* chore: remove maybeVirtualHtmlSet (#8010) ([e85164e](https://github.com/vitejs/vite/commit/e85164e)), closes [#8010](https://github.com/vitejs/vite/issues/8010)
+
+
+
+## 2.9.7 (2022-05-02)
+
+* chore: update license ([d58c030](https://github.com/vitejs/vite/commit/d58c030))
+* chore(css): catch postcss config error (fix #2793) (#7934) ([7f535ac](https://github.com/vitejs/vite/commit/7f535ac)), closes [#2793](https://github.com/vitejs/vite/issues/2793) [#7934](https://github.com/vitejs/vite/issues/7934)
+* chore(deps): update all non-major dependencies (#7949) ([b877d30](https://github.com/vitejs/vite/commit/b877d30)), closes [#7949](https://github.com/vitejs/vite/issues/7949)
+* fix: inject esbuild helpers in IIFE and UMD wrappers (#7948) ([f7d2d71](https://github.com/vitejs/vite/commit/f7d2d71)), closes [#7948](https://github.com/vitejs/vite/issues/7948)
+* fix: inline css hash (#7974) ([f6ae60d](https://github.com/vitejs/vite/commit/f6ae60d)), closes [#7974](https://github.com/vitejs/vite/issues/7974)
+* fix: inline style hmr, transform style code inplace (#7869) ([a30a548](https://github.com/vitejs/vite/commit/a30a548)), closes [#7869](https://github.com/vitejs/vite/issues/7869)
+* fix: use NODE_ENV in optimizer (#7673) ([50672e4](https://github.com/vitejs/vite/commit/50672e4)), closes [#7673](https://github.com/vitejs/vite/issues/7673)
+* fix(css): clean comments before hoist at rules (#7924) ([e48827f](https://github.com/vitejs/vite/commit/e48827f)), closes [#7924](https://github.com/vitejs/vite/issues/7924)
+* fix(css): dynamic import css in package fetches removed js (fixes #7955, #6823) (#7969) ([025eebf](https://github.com/vitejs/vite/commit/025eebf)), closes [#7955](https://github.com/vitejs/vite/issues/7955) [#6823](https://github.com/vitejs/vite/issues/6823) [#7969](https://github.com/vitejs/vite/issues/7969)
+* fix(css): inline css module when ssr, minify issue (fix #5471) (#7807) ([cf8a48a](https://github.com/vitejs/vite/commit/cf8a48a)), closes [#5471](https://github.com/vitejs/vite/issues/5471) [#7807](https://github.com/vitejs/vite/issues/7807)
+* fix(css): sourcemap crash with postcss (#7982) ([7f9f8f1](https://github.com/vitejs/vite/commit/7f9f8f1)), closes [#7982](https://github.com/vitejs/vite/issues/7982)
+* fix(css): support postcss.config.ts (#7935) ([274c10e](https://github.com/vitejs/vite/commit/274c10e)), closes [#7935](https://github.com/vitejs/vite/issues/7935)
+* fix(ssr): failed ssrLoadModule call throws same error (#7177) ([891e7fc](https://github.com/vitejs/vite/commit/891e7fc)), closes [#7177](https://github.com/vitejs/vite/issues/7177)
+* fix(worker): import.meta.* (#7706) ([b092697](https://github.com/vitejs/vite/commit/b092697)), closes [#7706](https://github.com/vitejs/vite/issues/7706)
+* docs: `server.origin` config trailing slash (fix #6622) (#7865) ([5c1ee5a](https://github.com/vitejs/vite/commit/5c1ee5a)), closes [#6622](https://github.com/vitejs/vite/issues/6622) [#7865](https://github.com/vitejs/vite/issues/7865)
+
+
+
+## 2.9.6 (2022-04-26)
+
+* fix: `apply` condition skipped for nested plugins (#7741) ([1f2ca53](https://github.com/vitejs/vite/commit/1f2ca53)), closes [#7741](https://github.com/vitejs/vite/issues/7741)
+* fix: clean string regexp (#7871) ([ecc78bc](https://github.com/vitejs/vite/commit/ecc78bc)), closes [#7871](https://github.com/vitejs/vite/issues/7871)
+* fix: escape character in string regexp match (#7834) ([1d468c8](https://github.com/vitejs/vite/commit/1d468c8)), closes [#7834](https://github.com/vitejs/vite/issues/7834)
+* fix: HMR propagation of HTML changes (fix #7870) (#7895) ([1f7855c](https://github.com/vitejs/vite/commit/1f7855c)), closes [#7870](https://github.com/vitejs/vite/issues/7870) [#7895](https://github.com/vitejs/vite/issues/7895)
+* fix: modulepreload polyfill only during build (fix #4786) (#7816) ([709776f](https://github.com/vitejs/vite/commit/709776f)), closes [#4786](https://github.com/vitejs/vite/issues/4786) [#7816](https://github.com/vitejs/vite/issues/7816)
+* fix: new SharedWorker syntax (#7800) ([474d5c2](https://github.com/vitejs/vite/commit/474d5c2)), closes [#7800](https://github.com/vitejs/vite/issues/7800)
+* fix: node v18 support (#7812) ([fc89057](https://github.com/vitejs/vite/commit/fc89057)), closes [#7812](https://github.com/vitejs/vite/issues/7812)
+* fix: preview jsdoc params (#7903) ([e474381](https://github.com/vitejs/vite/commit/e474381)), closes [#7903](https://github.com/vitejs/vite/issues/7903)
+* fix: replace import.meta.url correctly (#7792) ([12d1194](https://github.com/vitejs/vite/commit/12d1194)), closes [#7792](https://github.com/vitejs/vite/issues/7792)
+* fix: set `isSelfAccepting` to `false` for any asset not processed by importAnalysis (#7898) ([0d2089c](https://github.com/vitejs/vite/commit/0d2089c)), closes [#7898](https://github.com/vitejs/vite/issues/7898)
+* fix: spelling mistakes (#7883) ([54728e3](https://github.com/vitejs/vite/commit/54728e3)), closes [#7883](https://github.com/vitejs/vite/issues/7883)
+* fix: ssr.noExternal with boolean values (#7813) ([0b2d307](https://github.com/vitejs/vite/commit/0b2d307)), closes [#7813](https://github.com/vitejs/vite/issues/7813)
+* fix: style use string instead of js import (#7786) ([ba43c29](https://github.com/vitejs/vite/commit/ba43c29)), closes [#7786](https://github.com/vitejs/vite/issues/7786)
+* fix: update sourcemap in importAnalysisBuild (#7825) ([d7540c8](https://github.com/vitejs/vite/commit/d7540c8)), closes [#7825](https://github.com/vitejs/vite/issues/7825)
+* fix(ssr): rewrite dynamic class method name (fix #7751) (#7757) ([b89974a](https://github.com/vitejs/vite/commit/b89974a)), closes [#7751](https://github.com/vitejs/vite/issues/7751) [#7757](https://github.com/vitejs/vite/issues/7757)
+* chore: code structure (#7790) ([5f7fe00](https://github.com/vitejs/vite/commit/5f7fe00)), closes [#7790](https://github.com/vitejs/vite/issues/7790)
+* chore: fix worker sourcemap output style (#7805) ([17f3be7](https://github.com/vitejs/vite/commit/17f3be7)), closes [#7805](https://github.com/vitejs/vite/issues/7805)
+* chore(deps): update all non-major dependencies (#7780) ([eba9d05](https://github.com/vitejs/vite/commit/eba9d05)), closes [#7780](https://github.com/vitejs/vite/issues/7780)
+* chore(deps): update all non-major dependencies (#7847) ([e29d1d9](https://github.com/vitejs/vite/commit/e29d1d9)), closes [#7847](https://github.com/vitejs/vite/issues/7847)
+* feat: enable optimizeDeps.esbuildOptions.loader (#6840) ([af8ca60](https://github.com/vitejs/vite/commit/af8ca60)), closes [#6840](https://github.com/vitejs/vite/issues/6840)
+
+
+
+## 2.9.5 (2022-04-14)
+
+* fix: revert #7582, fix #7721 and #7736 (#7737) ([fa86d69](https://github.com/vitejs/vite/commit/fa86d69)), closes [#7721](https://github.com/vitejs/vite/issues/7721) [#7736](https://github.com/vitejs/vite/issues/7736) [#7737](https://github.com/vitejs/vite/issues/7737)
+* chore: format css minify esbuild error (#7731) ([c445075](https://github.com/vitejs/vite/commit/c445075)), closes [#7731](https://github.com/vitejs/vite/issues/7731)
+
+
+
+## 2.9.4 (2022-04-13)
+
+* fix: handle url imports with semicolon (fix #7717) (#7718) ([a5c2a78](https://github.com/vitejs/vite/commit/a5c2a78)), closes [#7717](https://github.com/vitejs/vite/issues/7717) [#7718](https://github.com/vitejs/vite/issues/7718)
+
+
+
+## 2.9.3 (2022-04-13)
+
+* fix: revert #7665 (#7716) ([26862c4](https://github.com/vitejs/vite/commit/26862c4)), closes [#7665](https://github.com/vitejs/vite/issues/7665) [#7716](https://github.com/vitejs/vite/issues/7716)
+
+
+
+## 2.9.2 (2022-04-13)
+
+* fix: `$ vite preview` 404 handling (#7665) ([66b6dc5](https://github.com/vitejs/vite/commit/66b6dc5)), closes [#7665](https://github.com/vitejs/vite/issues/7665)
+* fix: build should also respect esbuild=false config (#7602) ([2dc0e80](https://github.com/vitejs/vite/commit/2dc0e80)), closes [#7602](https://github.com/vitejs/vite/issues/7602)
+* fix: default value of assetsDir option (#7703) ([83d32d9](https://github.com/vitejs/vite/commit/83d32d9)), closes [#7703](https://github.com/vitejs/vite/issues/7703)
+* fix: detect env hmr (#7595) ([212d454](https://github.com/vitejs/vite/commit/212d454)), closes [#7595](https://github.com/vitejs/vite/issues/7595)
+* fix: EACCES permission denied due to resolve new paths default (#7612) ([1dd019f](https://github.com/vitejs/vite/commit/1dd019f)), closes [#7612](https://github.com/vitejs/vite/issues/7612)
+* fix: fix HMR propagation when imports not analyzed (#7561) ([57e7914](https://github.com/vitejs/vite/commit/57e7914)), closes [#7561](https://github.com/vitejs/vite/issues/7561)
+* fix: nested comments and strings, new regexp utils (#7650) ([93900f0](https://github.com/vitejs/vite/commit/93900f0)), closes [#7650](https://github.com/vitejs/vite/issues/7650)
+* fix: revert optimizeDeps false, keep optimizedDeps.disabled (#7715) ([ba9a1ff](https://github.com/vitejs/vite/commit/ba9a1ff)), closes [#7715](https://github.com/vitejs/vite/issues/7715)
+* fix: update watch mode (#7132) ([9ed1672](https://github.com/vitejs/vite/commit/9ed1672)), closes [#7132](https://github.com/vitejs/vite/issues/7132)
+* fix: update ws types (#7605) ([b620587](https://github.com/vitejs/vite/commit/b620587)), closes [#7605](https://github.com/vitejs/vite/issues/7605)
+* fix: use correct proxy config in preview (#7604) ([cf59005](https://github.com/vitejs/vite/commit/cf59005)), closes [#7604](https://github.com/vitejs/vite/issues/7604)
+* fix(css): hoist charset (#7678) ([29e622c](https://github.com/vitejs/vite/commit/29e622c)), closes [#7678](https://github.com/vitejs/vite/issues/7678)
+* fix(css): include inline css module in bundle (#7591) ([45b9273](https://github.com/vitejs/vite/commit/45b9273)), closes [#7591](https://github.com/vitejs/vite/issues/7591)
+* fix(deps): update all non-major dependencies (#7668) ([485263c](https://github.com/vitejs/vite/commit/485263c)), closes [#7668](https://github.com/vitejs/vite/issues/7668)
+* fix(less): handles rewriting relative paths passed Less's `data-uri` function. (#7400) ([08e39b7](https://github.com/vitejs/vite/commit/08e39b7)), closes [#7400](https://github.com/vitejs/vite/issues/7400)
+* fix(resolver): skip known ESM entries when resolving a `require` call (#7582) ([5d6ea8e](https://github.com/vitejs/vite/commit/5d6ea8e)), closes [#7582](https://github.com/vitejs/vite/issues/7582)
+* fix(ssr): properly transform export default with expressions (#7705) ([d6830e3](https://github.com/vitejs/vite/commit/d6830e3)), closes [#7705](https://github.com/vitejs/vite/issues/7705)
+* feat: clean string module lex string template (#7667) ([dfce283](https://github.com/vitejs/vite/commit/dfce283)), closes [#7667](https://github.com/vitejs/vite/issues/7667)
+* feat: explicit the word boundary (#6876) ([7ddbf96](https://github.com/vitejs/vite/commit/7ddbf96)), closes [#6876](https://github.com/vitejs/vite/issues/6876)
+* feat: optimizeDeps.disabled (#7646) ([48e038c](https://github.com/vitejs/vite/commit/48e038c)), closes [#7646](https://github.com/vitejs/vite/issues/7646)
+* chore: fix term cases (#7553) ([c296130](https://github.com/vitejs/vite/commit/c296130)), closes [#7553](https://github.com/vitejs/vite/issues/7553)
+* chore: revert removed line in #7698 ([7e6a2c8](https://github.com/vitejs/vite/commit/7e6a2c8)), closes [#7698](https://github.com/vitejs/vite/issues/7698)
+* chore: type unknown env as any (#7702) ([23fdef1](https://github.com/vitejs/vite/commit/23fdef1)), closes [#7702](https://github.com/vitejs/vite/issues/7702)
+* chore(deps): update all non-major dependencies (#7603) ([fc51a15](https://github.com/vitejs/vite/commit/fc51a15)), closes [#7603](https://github.com/vitejs/vite/issues/7603)
+* perf(css): hoist at rules with regex (#7691) ([8858180](https://github.com/vitejs/vite/commit/8858180)), closes [#7691](https://github.com/vitejs/vite/issues/7691)
+* refactor: esbuild handles `target` and `useDefineForClassFields` (#7698) ([0c928aa](https://github.com/vitejs/vite/commit/0c928aa)), closes [#7698](https://github.com/vitejs/vite/issues/7698)
+* docs: update release notes (#7563) ([a74bd7b](https://github.com/vitejs/vite/commit/a74bd7b)), closes [#7563](https://github.com/vitejs/vite/issues/7563)
+
+
+
## 2.9.1 (2022-03-31)
* fix: allow port 0 to be provided to server (#7530) ([173e4c9](https://github.com/vitejs/vite/commit/173e4c9)), closes [#7530](https://github.com/vitejs/vite/issues/7530)
@@ -21,7 +130,7 @@ Vite now supports CSS sourcemaps [#7173](https://github.com/vitejs/vite/issues/7
### Avoid splitting vendor chunks by default
-Vite's default chunking strategy was a good fit for most SPAs, but it wasn't ideal in some other use cases. Vite doesn't have enough context to make the best decision here, so in Vite 2.9 the previous chunking strategy is now opt-in [#6534](https://github.com/vitejs/vite/issues/6534) and Vite will no longer split vendor libs in a separate chunk.
+Vite's default chunking strategy was a good fit for most SPAs, but it wasn't ideal in some other use cases. Vite doesn't have enough context to make the best decision here, so in Vite 2.9 the previous chunking strategy is now [opt-in](https://vitejs.dev/guide/build.html#chunking-strategy) [#6534](https://github.com/vitejs/vite/issues/6534) and Vite will no longer split vendor libs in a separate chunk.
### Web Workers enhancements
@@ -37,6 +146,9 @@ const examples = import.meta.globEager('./examples/*.html', { as: 'raw' })
The `{ assert: { type: 'raw' }}` syntax introduced in v2.8 has been deprecated. See [#7017](https://github.com/vitejs/vite/issues/7017) for more information.
+### `envDir` changes
+
+The `envDir` now correctly loads `.env` files in the specified directory only (defaults to `root`). Previously, it would load files above the directory, which imposed security issues. If you had relied on the previous behaviour, make sure you move your `.env` files to the correct directory, or configure the `envDir` option.
### New tools for Plugin and Framework Authors
@@ -325,7 +437,7 @@ See [2.9.0-beta.0 changelog](https://github.com/vitejs/vite/blob/v2.9.0-beta.0/p
### Default preview port
-New default port for `vite preview` is 4173 (avoid conflicts in MacOS that took over the 5000 port)
+New default port for `vite preview` is 4173 (avoid conflicts in macOS that took over the 5000 port)
### Workers using standard syntax
diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md
index ccff3f1508a73b..2b43883f1b2b67 100644
--- a/packages/vite/LICENSE.md
+++ b/packages/vite/LICENSE.md
@@ -237,6 +237,33 @@ Repository: git+https://github.com/ampproject/remapping.git
---------------------------------------
+## @jridgewell/gen-mapping
+License: MIT
+By: Justin Ridgewell
+Repository: https://github.com/jridgewell/gen-mapping
+
+> Copyright 2022 Justin Ridgewell
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+> SOFTWARE.
+
+---------------------------------------
+
## @jridgewell/resolve-uri
License: MIT
By: Justin Ridgewell
@@ -264,6 +291,33 @@ Repository: https://github.com/jridgewell/resolve-uri
---------------------------------------
+## @jridgewell/set-array
+License: MIT
+By: Justin Ridgewell
+Repository: https://github.com/jridgewell/set-array
+
+> Copyright 2022 Justin Ridgewell
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in
+> all copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+> SOFTWARE.
+
+---------------------------------------
+
## @jridgewell/sourcemap-codec
License: MIT
By: Rich Harris
@@ -577,7 +631,7 @@ Repository: https://github.com/acornjs/acorn.git
> MIT License
>
-> Copyright (C) 2012-2020 by various contributors (see AUTHORS)
+> Copyright (C) 2012-2022 by various contributors (see AUTHORS)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
@@ -3411,6 +3465,35 @@ Repository: chalk/strip-ansi
---------------------------------------
+## strip-literal
+License: MIT
+By: Anthony Fu
+Repository: git+https://github.com/antfu/strip-literal.git
+
+> MIT License
+>
+> Copyright (c) 2022 Anthony Fu
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in all
+> copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+> SOFTWARE.
+
+---------------------------------------
+
## to-regex-range
License: MIT
By: Jon Schlinkert, Rouven Weßling
@@ -3523,6 +3606,34 @@ Repository: git+https://github.com/dominikg/tsconfck.git
---------------------------------------
+## ufo
+License: MIT
+Repository: unjs/ufo
+
+> MIT License
+>
+> Copyright (c) 2020 Nuxt Contrib
+>
+> Permission is hereby granted, free of charge, to any person obtaining a copy
+> of this software and associated documentation files (the "Software"), to deal
+> in the Software without restriction, including without limitation the rights
+> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+> copies of the Software, and to permit persons to whom the Software is
+> furnished to do so, subject to the following conditions:
+>
+> The above copyright notice and this permission notice shall be included in all
+> copies or substantial portions of the Software.
+>
+> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+> SOFTWARE.
+
+---------------------------------------
+
## unpipe
License: MIT
By: Douglas Christopher Wilson
diff --git a/packages/vite/client.d.ts b/packages/vite/client.d.ts
index aaac1ea986251d..af8e6a6f9d1494 100644
--- a/packages/vite/client.d.ts
+++ b/packages/vite/client.d.ts
@@ -1,4 +1,3 @@
-///
///
// CSS modules
diff --git a/packages/vite/package.json b/packages/vite/package.json
index 1a2aeddef3f42d..178a95b154b8a2 100644
--- a/packages/vite/package.json
+++ b/packages/vite/package.json
@@ -1,6 +1,6 @@
{
"name": "vite",
- "version": "2.9.1",
+ "version": "2.9.8",
"license": "MIT",
"author": "Evan You",
"description": "Native-ESM powered web dev build tool",
@@ -17,7 +17,7 @@
"types"
],
"engines": {
- "node": ">=12.2.0"
+ "node": ">=14.6.0"
},
"repository": {
"type": "git",
@@ -43,26 +43,26 @@
},
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
"dependencies": {
- "esbuild": "^0.14.27",
- "postcss": "^8.4.12",
+ "esbuild": "^0.14.38",
+ "postcss": "^8.4.13",
"resolve": "^1.22.0",
- "rollup": "^2.59.0"
+ "rollup": "^2.72.1"
},
"optionalDependencies": {
"fsevents": "~2.3.2"
},
"devDependencies": {
- "@ampproject/remapping": "^2.1.2",
- "@babel/parser": "^7.17.8",
- "@babel/types": "^7.17.0",
- "@jridgewell/trace-mapping": "^0.3.4",
+ "@ampproject/remapping": "^2.2.0",
+ "@babel/parser": "^7.17.10",
+ "@babel/types": "^7.17.10",
+ "@jridgewell/trace-mapping": "^0.3.10",
"@rollup/plugin-alias": "^3.1.9",
- "@rollup/plugin-commonjs": "^21.0.3",
- "@rollup/plugin-dynamic-import-vars": "^1.4.2",
+ "@rollup/plugin-commonjs": "^21.1.0",
+ "@rollup/plugin-dynamic-import-vars": "^1.4.3",
"@rollup/plugin-json": "^4.1.0",
- "@rollup/plugin-node-resolve": "13.1.3",
- "@rollup/plugin-typescript": "^8.3.1",
- "@rollup/pluginutils": "^4.2.0",
+ "@rollup/plugin-node-resolve": "13.2.1",
+ "@rollup/plugin-typescript": "^8.3.2",
+ "@rollup/pluginutils": "^4.2.1",
"@types/convert-source-map": "^1.5.2",
"@types/cross-spawn": "^6.0.2",
"@types/debug": "^4.1.7",
@@ -71,13 +71,13 @@
"@types/less": "^3.0.3",
"@types/micromatch": "^4.0.2",
"@types/mime": "^2.0.3",
- "@types/node": "^16.11.26",
- "@types/resolve": "^1.20.1",
+ "@types/node": "^17.0.31",
+ "@types/resolve": "^1.20.2",
"@types/sass": "~1.43.1",
- "@types/stylus": "^0.48.36",
+ "@types/stylus": "^0.48.37",
"@types/ws": "^8.5.3",
- "@vue/compiler-dom": "^3.2.31",
- "acorn": "^8.7.0",
+ "@vue/compiler-dom": "^3.2.33",
+ "acorn": "^8.7.1",
"cac": "6.7.9",
"chokidar": "^3.5.3",
"connect": "^3.7.0",
@@ -88,7 +88,7 @@
"debug": "^4.3.4",
"dotenv": "^14.3.2",
"dotenv-expand": "^5.1.0",
- "es-module-lexer": "^0.10.4",
+ "es-module-lexer": "^0.10.5",
"estree-walker": "^2.0.2",
"etag": "^1.8.1",
"fast-glob": "^3.2.11",
@@ -98,25 +98,27 @@
"magic-string": "^0.26.1",
"micromatch": "^4.0.5",
"mrmime": "^1.0.0",
- "node-forge": "^1.3.0",
+ "node-forge": "^1.3.1",
"okie": "^1.0.1",
"open": "^8.4.0",
"periscopic": "^2.0.3",
"picocolors": "^1.0.0",
"postcss-import": "^14.1.0",
- "postcss-load-config": "^3.1.3",
+ "postcss-load-config": "^3.1.4",
"postcss-modules": "^4.3.1",
"resolve.exports": "^1.1.0",
- "rollup-plugin-license": "^2.6.1",
+ "rollup-plugin-license": "^2.7.0",
"sirv": "^2.0.2",
"source-map-js": "^1.0.2",
"source-map-support": "^0.5.21",
"strip-ansi": "^6.0.1",
- "terser": "^5.12.1",
- "tsconfck": "^1.2.1",
- "tslib": "^2.3.1",
+ "strip-literal": "^0.3.0",
+ "terser": "^5.13.1",
+ "tsconfck": "^1.2.2",
+ "tslib": "^2.4.0",
"types": "link:./types",
- "ws": "^8.5.0"
+ "ufo": "^0.8.4",
+ "ws": "^8.6.0"
},
"peerDependencies": {
"less": "*",
diff --git a/packages/vite/rollup.config.js b/packages/vite/rollup.config.js
index 31ab56cd07e02e..93f4f33bdec398 100644
--- a/packages/vite/rollup.config.js
+++ b/packages/vite/rollup.config.js
@@ -171,6 +171,11 @@ const createNodeConfig = (isProduction) => {
'lilconfig/dist/index.js': {
pattern: /: require,/g,
replacement: `: eval('require'),`
+ },
+ // postcss-load-config calls require after register ts-node
+ 'postcss-load-config/src/index.js': {
+ src: `require(configFile)`,
+ replacement: `eval('require')(configFile)`
}
}),
commonjs({
diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts
index 420d084ef9a981..48917204d8c291 100644
--- a/packages/vite/src/client/client.ts
+++ b/packages/vite/src/client/client.ts
@@ -106,6 +106,7 @@ async function handleMessage(payload: HMRPayload) {
const payloadPath = base + payload.path.slice(1)
if (
pagePath === payloadPath ||
+ payload.path === '/index.html' ||
(pagePath.endsWith('/') && pagePath + 'index.html' === payloadPath)
) {
location.reload()
@@ -432,13 +433,6 @@ export function createHotContext(ownerPath: string): ViteHotContext {
}
},
- acceptDeps() {
- throw new Error(
- `hot.acceptDeps() is deprecated. ` +
- `Use hot.accept() with the same signature instead.`
- )
- },
-
dispose(cb) {
disposeMap.set(ownerPath, cb)
},
diff --git a/packages/vite/src/node/__tests__/asset.spec.ts b/packages/vite/src/node/__tests__/asset.spec.ts
index 6e6b969bcbd38c..8727aa6485eb26 100644
--- a/packages/vite/src/node/__tests__/asset.spec.ts
+++ b/packages/vite/src/node/__tests__/asset.spec.ts
@@ -1,3 +1,4 @@
+import { describe, test, expect } from 'vitest'
import { assetFileNamesToFileName, getAssetHash } from '../plugins/asset'
describe('getAssetHash', () => {
diff --git a/packages/vite/src/node/__tests__/build.spec.ts b/packages/vite/src/node/__tests__/build.spec.ts
index b3ef37e64fd28e..b49847f1d955a4 100644
--- a/packages/vite/src/node/__tests__/build.spec.ts
+++ b/packages/vite/src/node/__tests__/build.spec.ts
@@ -1,5 +1,13 @@
+import type { LibraryFormats, LibraryOptions } from '../build'
import { resolveLibFilename } from '../build'
import { resolve } from 'path'
+import { describe, test, expect } from 'vitest'
+
+type FormatsToFileNames = [LibraryFormats, string][]
+const baseLibOptions: LibraryOptions = {
+ fileName: 'my-lib',
+ entry: 'mylib.js'
+}
describe('resolveLibFilename', () => {
test('custom filename function', () => {
@@ -25,7 +33,7 @@ describe('resolveLibFilename', () => {
resolve(__dirname, 'packages/name')
)
- expect(filename).toBe('custom-filename.es.js')
+ expect(filename).toBe('custom-filename.es.mjs')
})
test('package name as filename', () => {
@@ -37,7 +45,7 @@ describe('resolveLibFilename', () => {
resolve(__dirname, 'packages/name')
)
- expect(filename).toBe('mylib.es.js')
+ expect(filename).toBe('mylib.es.mjs')
})
test('custom filename and no package name', () => {
@@ -50,7 +58,7 @@ describe('resolveLibFilename', () => {
resolve(__dirname, 'packages/noname')
)
- expect(filename).toBe('custom-filename.es.js')
+ expect(filename).toBe('custom-filename.es.mjs')
})
test('missing filename', () => {
@@ -64,4 +72,42 @@ describe('resolveLibFilename', () => {
)
}).toThrow()
})
+
+ test('commonjs package extensions', () => {
+ const formatsToFilenames: FormatsToFileNames = [
+ ['es', 'my-lib.es.mjs'],
+ ['umd', 'my-lib.umd.js'],
+ ['cjs', 'my-lib.cjs.js'],
+ ['iife', 'my-lib.iife.js']
+ ]
+
+ for (const [format, expectedFilename] of formatsToFilenames) {
+ const filename = resolveLibFilename(
+ baseLibOptions,
+ format,
+ resolve(__dirname, 'packages/noname')
+ )
+
+ expect(filename).toBe(expectedFilename)
+ }
+ })
+
+ test('module package extensions', () => {
+ const formatsToFilenames: FormatsToFileNames = [
+ ['es', 'my-lib.es.js'],
+ ['umd', 'my-lib.umd.cjs'],
+ ['cjs', 'my-lib.cjs.cjs'],
+ ['iife', 'my-lib.iife.js']
+ ]
+
+ for (const [format, expectedFilename] of formatsToFilenames) {
+ const filename = resolveLibFilename(
+ baseLibOptions,
+ format,
+ resolve(__dirname, 'packages/module')
+ )
+
+ expect(filename).toBe(expectedFilename)
+ }
+ })
})
diff --git a/packages/vite/src/node/__tests__/config.spec.ts b/packages/vite/src/node/__tests__/config.spec.ts
index dd427c19433475..83995ab28adcbd 100644
--- a/packages/vite/src/node/__tests__/config.spec.ts
+++ b/packages/vite/src/node/__tests__/config.spec.ts
@@ -1,6 +1,7 @@
import type { InlineConfig } from '..'
import type { UserConfigExport, UserConfig } from '../config'
import { mergeConfig, resolveConfig, resolveEnvPrefix } from '../config'
+import { describe, test, expect } from 'vitest'
describe('mergeConfig', () => {
test('handles configs with different alias schemas', () => {
@@ -157,51 +158,29 @@ describe('mergeConfig', () => {
expect(mergeConfig(baseConfig, newConfig)).toEqual(mergedConfig)
})
-})
-
-describe('resolveConfig', () => {
- beforeAll(() => {
- // silence deprecation warning
- jest.spyOn(console, 'warn').mockImplementation(() => {})
- })
- afterAll(() => {
- jest.clearAllMocks()
- })
-
- test('copies optimizeDeps.keepNames to esbuildOptions.keepNames', async () => {
- const config: InlineConfig = {
- optimizeDeps: {
- keepNames: false
+ test('handles ssr.noExternal', () => {
+ const baseConfig = {
+ ssr: {
+ noExternal: true
}
}
- expect(await resolveConfig(config, 'serve')).toMatchObject({
- optimizeDeps: {
- esbuildOptions: {
- keepNames: false
- }
+ const newConfig = {
+ ssr: {
+ noExternal: ['foo']
}
- })
- })
+ }
- test('uses esbuildOptions.keepNames if set', async () => {
- const config: InlineConfig = {
- optimizeDeps: {
- keepNames: true,
- esbuildOptions: {
- keepNames: false
- }
+ const mergedConfig = {
+ ssr: {
+ noExternal: true
}
}
- expect(await resolveConfig(config, 'serve')).toMatchObject({
- optimizeDeps: {
- esbuildOptions: {
- keepNames: false
- }
- }
- })
+ // merging either ways, `ssr.noExternal: true` should take highest priority
+ expect(mergeConfig(baseConfig, newConfig)).toEqual(mergedConfig)
+ expect(mergeConfig(newConfig, baseConfig)).toEqual(mergedConfig)
})
})
diff --git a/packages/vite/src/node/__tests__/dev.spec.ts b/packages/vite/src/node/__tests__/dev.spec.ts
index 3eefd7b4b903c1..cdb0fc123f4b4f 100644
--- a/packages/vite/src/node/__tests__/dev.spec.ts
+++ b/packages/vite/src/node/__tests__/dev.spec.ts
@@ -1,4 +1,5 @@
import { resolveConfig } from '..'
+import { describe, test, expect } from 'vitest'
describe('resolveBuildOptions in dev', () => {
test('build.rollupOptions should not have input in lib', async () => {
diff --git a/packages/vite/src/node/__tests__/packages/module/package.json b/packages/vite/src/node/__tests__/packages/module/package.json
new file mode 100644
index 00000000000000..3dbc1ca591c055
--- /dev/null
+++ b/packages/vite/src/node/__tests__/packages/module/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "module"
+}
diff --git a/packages/vite/src/node/__tests__/plugins/css.spec.ts b/packages/vite/src/node/__tests__/plugins/css.spec.ts
index 539ec2f1af1810..eeacaf482b0c31 100644
--- a/packages/vite/src/node/__tests__/plugins/css.spec.ts
+++ b/packages/vite/src/node/__tests__/plugins/css.spec.ts
@@ -1,7 +1,8 @@
-import { cssUrlRE, cssPlugin } from '../../plugins/css'
+import { cssUrlRE, cssPlugin, hoistAtRules } from '../../plugins/css'
import { resolveConfig } from '../../config'
import fs from 'fs'
import path from 'path'
+import { describe, vi, test, expect } from 'vitest'
describe('search css url function', () => {
test('some spaces before it', () => {
@@ -69,7 +70,7 @@ describe('css path resolutions', () => {
await buildStart.call({})
- const mockFs = jest
+ const mockFs = vi
.spyOn(fs, 'readFile')
// @ts-ignore jest.spyOn not recognize overrided `fs.readFile` definition.
.mockImplementationOnce((p, encoding, callback) => {
@@ -114,3 +115,95 @@ describe('css path resolutions', () => {
mockFs.mockReset()
})
})
+
+describe('hoist @ rules', () => {
+ test('hoist @import', async () => {
+ const css = `.foo{color:red;}@import "bla";`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(`@import "bla";.foo{color:red;}`)
+ })
+
+ test('hoist @import url with semicolon', async () => {
+ const css = `.foo{color:red;}@import url("bla;bla");`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(`@import url("bla;bla");.foo{color:red;}`)
+ })
+
+ test('hoist @import url data with semicolon', async () => {
+ const css = `.foo{color:red;}@import url(data:image/png;base64,iRxVB0);`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(
+ `@import url(data:image/png;base64,iRxVB0);.foo{color:red;}`
+ )
+ })
+
+ test('hoist @import with semicolon in quotes', async () => {
+ const css = `.foo{color:red;}@import "bla;bar";`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(`@import "bla;bar";.foo{color:red;}`)
+ })
+
+ test('hoist @charset', async () => {
+ const css = `.foo{color:red;}@charset "utf-8";`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(`@charset "utf-8";.foo{color:red;}`)
+ })
+
+ test('hoist one @charset only', async () => {
+ const css = `.foo{color:red;}@charset "utf-8";@charset "utf-8";`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(`@charset "utf-8";.foo{color:red;}`)
+ })
+
+ test('hoist @import and @charset', async () => {
+ const css = `.foo{color:red;}@import "bla";@charset "utf-8";.bar{color:green;}@import "baz";`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(
+ `@charset "utf-8";@import "bla";@import "baz";.foo{color:red;}.bar{color:green;}`
+ )
+ })
+
+ test('dont hoist @import in comments', async () => {
+ const css = `.foo{color:red;}/* @import "bla"; */@import "bar";`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(`@import "bar";.foo{color:red;}/* @import "bla"; */`)
+ })
+
+ test('dont hoist @charset in comments', async () => {
+ const css = `.foo{color:red;}/* @charset "utf-8"; */@charset "utf-8";`
+ const result = await hoistAtRules(css)
+ expect(result).toBe(
+ `@charset "utf-8";.foo{color:red;}/* @charset "utf-8"; */`
+ )
+ })
+
+ test('dont hoist @import and @charset in comments', async () => {
+ const css = `
+ .foo{color:red;}
+ /*
+ @import "bla";
+ */
+ @charset "utf-8";
+ /*
+ @charset "utf-8";
+ @import "bar";
+ */
+ @import "baz";
+ `
+ const result = await hoistAtRules(css)
+ expect(result).toBe(
+ `@charset "utf-8";@import "baz";
+ .foo{color:red;}
+ /*
+ @import "bla";
+ */
+
+ /*
+ @charset "utf-8";
+ @import "bar";
+ */
+
+ `
+ )
+ })
+})
diff --git a/packages/vite/src/node/__tests__/plugins/define.spec.ts b/packages/vite/src/node/__tests__/plugins/define.spec.ts
index 9a65f8f3a51cea..b9acc81cb790d5 100644
--- a/packages/vite/src/node/__tests__/plugins/define.spec.ts
+++ b/packages/vite/src/node/__tests__/plugins/define.spec.ts
@@ -1,3 +1,4 @@
+import { describe, test, expect } from 'vitest'
import { definePlugin } from '../../plugins/define'
import { resolveConfig } from '../../config'
diff --git a/packages/vite/src/node/__tests__/plugins/import.spec.ts b/packages/vite/src/node/__tests__/plugins/import.spec.ts
index f0341e81b50f3c..e232702d57d354 100644
--- a/packages/vite/src/node/__tests__/plugins/import.spec.ts
+++ b/packages/vite/src/node/__tests__/plugins/import.spec.ts
@@ -1,3 +1,4 @@
+import { describe, test, expect } from 'vitest'
import { transformCjsImport } from '../../plugins/importAnalysis'
describe('transformCjsImport', () => {
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap b/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap
new file mode 100644
index 00000000000000..23e511a50545f7
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap
@@ -0,0 +1,162 @@
+// Vitest Snapshot v1
+
+exports[`fixture > transform 1`] = `
+"import * as __vite_glob_1_0 from \\"./modules/a.ts\\"
+import * as __vite_glob_1_1 from \\"./modules/b.ts\\"
+import * as __vite_glob_1_2 from \\"./modules/index.ts\\"
+import { name as __vite_glob_3_0 } from \\"./modules/a.ts\\"
+import { name as __vite_glob_3_1 } from \\"./modules/b.ts\\"
+import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\"
+import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\"
+import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\"
+import \\"../../../../../../types/importMeta\\";
+export const basic = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),
+\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\")
+};
+export const basicEager = {
+\\"./modules/a.ts\\": __vite_glob_1_0,
+\\"./modules/b.ts\\": __vite_glob_1_1,
+\\"./modules/index.ts\\": __vite_glob_1_2
+};
+export const ignore = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\")
+};
+export const namedEager = {
+\\"./modules/a.ts\\": __vite_glob_3_0,
+\\"./modules/b.ts\\": __vite_glob_3_1,
+\\"./modules/index.ts\\": __vite_glob_3_2
+};
+export const namedDefault = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]),
+\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"])
+};
+export const eagerAs = {
+\\"./modules/a.ts\\": __vite_glob_5_0,
+\\"./modules/b.ts\\": __vite_glob_5_1
+};
+export const rawImportModule = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")
+};
+export const excludeSelf = {
+\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")
+};
+export const customQueryString = {
+\\"./sibling.ts\\": () => import(\\"./sibling.ts?custom\\")
+};
+export const customQueryObject = {
+\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true\\")
+};
+export const parent = {
+
+};
+export const rootMixedRelative = {
+\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url\\").then(m => m[\\"default\\"]),
+\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url\\").then(m => m[\\"default\\"]),
+\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url\\").then(m => m[\\"default\\"]),
+\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url\\").then(m => m[\\"default\\"]),
+\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url\\").then(m => m[\\"default\\"]),
+\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url\\").then(m => m[\\"default\\"])
+};
+export const cleverCwd1 = {
+\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\")
+};
+export const cleverCwd2 = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),
+\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"),
+\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\")
+};
+"
+`;
+
+exports[`fixture > transform with restoreQueryExtension 1`] = `
+"import * as __vite_glob_1_0 from \\"./modules/a.ts\\"
+import * as __vite_glob_1_1 from \\"./modules/b.ts\\"
+import * as __vite_glob_1_2 from \\"./modules/index.ts\\"
+import { name as __vite_glob_3_0 } from \\"./modules/a.ts\\"
+import { name as __vite_glob_3_1 } from \\"./modules/b.ts\\"
+import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\"
+import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\"
+import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\"
+import \\"../../../../../../types/importMeta\\";
+export const basic = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),
+\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\")
+};
+export const basicEager = {
+\\"./modules/a.ts\\": __vite_glob_1_0,
+\\"./modules/b.ts\\": __vite_glob_1_1,
+\\"./modules/index.ts\\": __vite_glob_1_2
+};
+export const ignore = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\")
+};
+export const namedEager = {
+\\"./modules/a.ts\\": __vite_glob_3_0,
+\\"./modules/b.ts\\": __vite_glob_3_1,
+\\"./modules/index.ts\\": __vite_glob_3_2
+};
+export const namedDefault = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]),
+\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"])
+};
+export const eagerAs = {
+\\"./modules/a.ts\\": __vite_glob_5_0,
+\\"./modules/b.ts\\": __vite_glob_5_1
+};
+export const rawImportModule = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")
+};
+export const excludeSelf = {
+\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")
+};
+export const customQueryString = {
+\\"./sibling.ts\\": () => import(\\"./sibling.ts?custom&lang.ts\\")
+};
+export const customQueryObject = {
+\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true&lang.ts\\")
+};
+export const parent = {
+
+};
+export const rootMixedRelative = {
+\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),
+\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),
+\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),
+\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url&lang.ts\\").then(m => m[\\"default\\"]),
+\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url&lang.ts\\").then(m => m[\\"default\\"]),
+\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url&lang.ts\\").then(m => m[\\"default\\"])
+};
+export const cleverCwd1 = {
+\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\")
+};
+export const cleverCwd2 = {
+\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),
+\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),
+\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"),
+\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\")
+};
+"
+`;
+
+exports[`fixture > virtual modules 1`] = `
+"{
+\\"/modules/a.ts\\": () => import(\\"/modules/a.ts\\"),
+\\"/modules/b.ts\\": () => import(\\"/modules/b.ts\\"),
+\\"/modules/index.ts\\": () => import(\\"/modules/index.ts\\")
+}
+{
+\\"/../fixture-b/a.ts\\": () => import(\\"/../fixture-b/a.ts\\"),
+\\"/../fixture-b/b.ts\\": () => import(\\"/../fixture-b/b.ts\\"),
+\\"/../fixture-b/index.ts\\": () => import(\\"/../fixture-b/index.ts\\")
+}"
+`;
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/.gitignore b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/.gitignore
new file mode 100644
index 00000000000000..2b9b8877da603f
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/.gitignore
@@ -0,0 +1 @@
+!/node_modules/
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts
new file mode 100644
index 00000000000000..4fed8828e5f418
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/index.ts
@@ -0,0 +1,69 @@
+import '../../../../../../types/importMeta'
+
+/* eslint-disable @typescript-eslint/comma-dangle */
+export interface ModuleType {
+ name: string
+}
+
+export const basic = import.meta.glob('./modules/*.ts')
+
+export const basicEager = import.meta.glob('./modules/*.ts', {
+ eager: true
+})
+
+export const ignore = import.meta.glob(['./modules/*.ts', '!**/index.ts'])
+
+export const namedEager = import.meta.glob('./modules/*.ts', {
+ eager: true,
+ import: 'name'
+})
+
+export const namedDefault = import.meta.glob('./modules/*.ts', {
+ import: 'default'
+})
+
+export const eagerAs = import.meta.glob(
+ ['./modules/*.ts', '!**/index.ts'],
+ { eager: true, as: 'raw' }
+)
+
+export const rawImportModule = import.meta.glob(
+ ['./modules/*.ts', '!**/index.ts'],
+ { as: 'raw', import: '*' }
+)
+
+export const excludeSelf = import.meta.glob(
+ './*.ts'
+ // for test: annotation contain ")"
+ /*
+ * for test: annotation contain ")"
+ * */
+)
+
+export const customQueryString = import.meta.glob('./*.ts', { query: 'custom' })
+
+export const customQueryObject = import.meta.glob('./*.ts', {
+ query: {
+ foo: 'bar',
+ raw: true
+ }
+})
+
+export const parent = import.meta.glob('../../playground/src/*.ts', {
+ as: 'url'
+})
+
+export const rootMixedRelative = import.meta.glob(
+ ['/*.ts', '../fixture-b/*.ts'],
+ { as: 'url' }
+)
+
+export const cleverCwd1 = import.meta.glob(
+ './node_modules/framework/**/*.page.js'
+)
+
+export const cleverCwd2 = import.meta.glob([
+ './modules/*.ts',
+ '../fixture-b/*.ts',
+ '!**/index.ts'
+])
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/a.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/a.ts
new file mode 100644
index 00000000000000..facd48a0875e65
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/a.ts
@@ -0,0 +1 @@
+export const name = 'a'
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/b.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/b.ts
new file mode 100644
index 00000000000000..0b1eb38d9087a2
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/b.ts
@@ -0,0 +1 @@
+export const name = 'b'
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/index.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/index.ts
new file mode 100644
index 00000000000000..25b59ae7d30714
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/modules/index.ts
@@ -0,0 +1,6 @@
+export { name as a } from './a'
+export { name as b } from './b'
+
+export const name = 'index'
+
+export default 'indexDefault'
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/node_modules/framework/pages/hello.page.js b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/node_modules/framework/pages/hello.page.js
new file mode 100644
index 00000000000000..cbe518a8e79477
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/node_modules/framework/pages/hello.page.js
@@ -0,0 +1,4 @@
+// A fake Page file. (This technique of globbing into `node_modules/`
+// is used by vite-plugin-ssr frameworks and Hydrogen.)
+
+export const a = 1
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/sibling.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/sibling.ts
new file mode 100644
index 00000000000000..b286816bf5d63a
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-a/sibling.ts
@@ -0,0 +1 @@
+export const name = 'I am your sibling!'
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/a.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/a.ts
new file mode 100644
index 00000000000000..facd48a0875e65
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/a.ts
@@ -0,0 +1 @@
+export const name = 'a'
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/b.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/b.ts
new file mode 100644
index 00000000000000..0b1eb38d9087a2
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/b.ts
@@ -0,0 +1 @@
+export const name = 'b'
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/index.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/index.ts
new file mode 100644
index 00000000000000..39bdbfd1a8befb
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture-b/index.ts
@@ -0,0 +1,2 @@
+export { name as a } from './a'
+export { name as b } from './b'
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts b/packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts
new file mode 100644
index 00000000000000..985263d91db85a
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts
@@ -0,0 +1,59 @@
+import { resolve } from 'path'
+import { promises as fs } from 'fs'
+import { describe, expect, it } from 'vitest'
+import { transformGlobImport } from '../../../plugins/importMetaGlob'
+import { transformWithEsbuild } from '../../../plugins/esbuild'
+
+describe('fixture', async () => {
+ const resolveId = (id: string) => id
+ const root = resolve(__dirname, '..')
+
+ it('transform', async () => {
+ const id = resolve(__dirname, './fixture-a/index.ts')
+ const code = (
+ await transformWithEsbuild(await fs.readFile(id, 'utf-8'), id)
+ ).code
+
+ expect(
+ (await transformGlobImport(code, id, root, resolveId))?.s.toString()
+ ).toMatchSnapshot()
+ })
+
+ it('virtual modules', async () => {
+ const root = resolve(__dirname, './fixture-a')
+ const code = [
+ "import.meta.glob('/modules/*.ts')",
+ "import.meta.glob(['/../fixture-b/*.ts'])"
+ ].join('\n')
+ expect(
+ (
+ await transformGlobImport(code, 'virtual:module', root, resolveId)
+ )?.s.toString()
+ ).toMatchSnapshot()
+
+ try {
+ await transformGlobImport(
+ "import.meta.glob('./modules/*.ts')",
+ 'virtual:module',
+ root,
+ resolveId
+ )
+ expect('no error').toBe('should throw an error')
+ } catch (err) {
+ expect(err).toMatchInlineSnapshot(
+ "[Error: In virtual modules, all globs must start with '/']"
+ )
+ }
+ })
+
+ it('transform with restoreQueryExtension', async () => {
+ const id = resolve(__dirname, './fixture-a/index.ts')
+ const code = (
+ await transformWithEsbuild(await fs.readFile(id, 'utf-8'), id)
+ ).code
+
+ expect(
+ (await transformGlobImport(code, id, root, resolveId, true))?.s.toString()
+ ).toMatchSnapshot()
+ })
+})
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/parse.test.ts b/packages/vite/src/node/__tests__/plugins/importGlob/parse.test.ts
new file mode 100644
index 00000000000000..df1e0d758e8849
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/parse.test.ts
@@ -0,0 +1,202 @@
+import { describe, expect, it } from 'vitest'
+import { parseImportGlob } from '../../../plugins/importMetaGlob'
+
+async function run(input: string) {
+ const items = await parseImportGlob(
+ input,
+ process.cwd(),
+ process.cwd(),
+ (id) => id
+ )
+ return items.map((i) => ({ globs: i.globs, options: i.options }))
+}
+
+async function runError(input: string) {
+ try {
+ await run(input)
+ } catch (e) {
+ return e
+ }
+}
+
+describe('parse positives', async () => {
+ it('basic', async () => {
+ expect(
+ await run(`
+ import.meta.importGlob(\'./modules/*.ts\')
+ `)
+ ).toMatchInlineSnapshot('[]')
+ })
+
+ it('array', async () => {
+ expect(
+ await run(`
+ import.meta.importGlob([\'./modules/*.ts\', './dir/*.{js,ts}\'])
+ `)
+ ).toMatchInlineSnapshot('[]')
+ })
+
+ it('options with multilines', async () => {
+ expect(
+ await run(`
+ import.meta.importGlob([
+ \'./modules/*.ts\',
+ "!./dir/*.{js,ts}"
+ ], {
+ eager: true,
+ import: 'named'
+ })
+ `)
+ ).toMatchInlineSnapshot('[]')
+ })
+
+ it('options with multilines', async () => {
+ expect(
+ await run(`
+ const modules = import.meta.glob(
+ '/dir/**'
+ // for test: annotation contain ")"
+ /*
+ * for test: annotation contain ")"
+ * */
+ )
+ `)
+ ).toMatchInlineSnapshot(`
+ [
+ {
+ "globs": [
+ "/dir/**",
+ ],
+ "options": {},
+ },
+ ]
+ `)
+ })
+
+ it('options query', async () => {
+ expect(
+ await run(`
+ const modules = import.meta.glob(
+ '/dir/**',
+ {
+ query: {
+ foo: 'bar',
+ raw: true,
+ }
+ }
+ )
+ `)
+ ).toMatchInlineSnapshot(`
+ [
+ {
+ "globs": [
+ "/dir/**",
+ ],
+ "options": {
+ "query": {
+ "foo": "bar",
+ "raw": true,
+ },
+ },
+ },
+ ]
+ `)
+ })
+})
+
+describe('parse negatives', async () => {
+ it('syntax error', async () => {
+ expect(await runError('import.meta.importGlob(')).toMatchInlineSnapshot(
+ 'undefined'
+ )
+ })
+
+ it('empty', async () => {
+ expect(await runError('import.meta.importGlob()')).toMatchInlineSnapshot(
+ 'undefined'
+ )
+ })
+
+ it('3 args', async () => {
+ expect(
+ await runError('import.meta.importGlob("", {}, {})')
+ ).toMatchInlineSnapshot('undefined')
+ })
+
+ it('in string', async () => {
+ expect(await runError('"import.meta.importGlob()"')).toBeUndefined()
+ })
+
+ it('variable', async () => {
+ expect(await runError('import.meta.importGlob(hey)')).toMatchInlineSnapshot(
+ 'undefined'
+ )
+ })
+
+ it('template', async () => {
+ // eslint-disable-next-line no-template-curly-in-string
+ expect(
+ await runError('import.meta.importGlob(`hi ${hey}`)')
+ ).toMatchInlineSnapshot('undefined')
+ })
+
+ it('be string', async () => {
+ expect(await runError('import.meta.importGlob(1)')).toMatchInlineSnapshot(
+ 'undefined'
+ )
+ })
+
+ it('be array variable', async () => {
+ expect(
+ await runError('import.meta.importGlob([hey])')
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError('import.meta.importGlob(["1", hey])')
+ ).toMatchInlineSnapshot('undefined')
+ })
+
+ it('options', async () => {
+ expect(
+ await runError('import.meta.importGlob("hey", hey)')
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError('import.meta.importGlob("hey", [])')
+ ).toMatchInlineSnapshot('undefined')
+ })
+
+ it('options props', async () => {
+ expect(
+ await runError('import.meta.importGlob("hey", { hey: 1 })')
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError('import.meta.importGlob("hey", { import: hey })')
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError('import.meta.importGlob("hey", { eager: 123 })')
+ ).toMatchInlineSnapshot('undefined')
+ })
+
+ it('options query', async () => {
+ expect(
+ await runError(
+ 'import.meta.importGlob("./*.js", { as: "raw", query: "hi" })'
+ )
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError('import.meta.importGlob("./*.js", { query: 123 })')
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError('import.meta.importGlob("./*.js", { query: { foo: {} } })')
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError(
+ 'import.meta.importGlob("./*.js", { query: { foo: hey } })'
+ )
+ ).toMatchInlineSnapshot('undefined')
+ expect(
+ await runError(
+ 'import.meta.importGlob("./*.js", { query: { foo: 123, ...a } })'
+ )
+ ).toMatchInlineSnapshot('undefined')
+ })
+})
diff --git a/packages/vite/src/node/__tests__/plugins/importGlob/utils.test.ts b/packages/vite/src/node/__tests__/plugins/importGlob/utils.test.ts
new file mode 100644
index 00000000000000..302df97ec92ede
--- /dev/null
+++ b/packages/vite/src/node/__tests__/plugins/importGlob/utils.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it } from 'vitest'
+import { getCommonBase } from '../../../plugins/importMetaGlob'
+
+describe('getCommonBase()', async () => {
+ it('basic', () => {
+ expect(getCommonBase(['/a/b/*.js', '/a/c/*.js'])).toBe('/a')
+ })
+ it('common base', () => {
+ expect(getCommonBase(['/a/b/**/*.vue', '/a/b/**/*.jsx'])).toBe('/a/b')
+ })
+ it('static file', () => {
+ expect(
+ getCommonBase(['/a/b/**/*.vue', '/a/b/**/*.jsx', '/a/b/foo.js'])
+ ).toBe('/a/b')
+ expect(getCommonBase(['/a/b/**/*.vue', '/a/b/**/*.jsx', '/a/foo.js'])).toBe(
+ '/a'
+ )
+ })
+ it('correct `scan()`', () => {
+ expect(getCommonBase(['/a/*.vue'])).toBe('/a')
+ expect(getCommonBase(['/a/some.vue'])).toBe('/a')
+ expect(getCommonBase(['/a/b/**/c/foo.vue', '/a/b/c/**/*.jsx'])).toBe('/a/b')
+ })
+ it('single', () => {
+ expect(getCommonBase(['/a/b/c/*.vue'])).toBe('/a/b/c')
+ expect(getCommonBase(['/a/b/c/foo.vue'])).toBe('/a/b/c')
+ })
+ it('no common base', () => {
+ expect(getCommonBase(['/a/b/*.js', '/c/a/b/*.js'])).toBe('/')
+ })
+})
diff --git a/packages/vite/src/node/__tests__/scan.spec.ts b/packages/vite/src/node/__tests__/scan.spec.ts
index db11bcc45b284c..8d5a275fca0292 100644
--- a/packages/vite/src/node/__tests__/scan.spec.ts
+++ b/packages/vite/src/node/__tests__/scan.spec.ts
@@ -1,5 +1,6 @@
import { scriptRE, commentRE, importsRE } from '../optimizer/scan'
import { multilineCommentsRE, singlelineCommentsRE } from '../utils'
+import { describe, test, expect } from 'vitest'
describe('optimizer-scan:script-test', () => {
const scriptContent = `import { defineComponent } from 'vue'
diff --git a/packages/vite/src/node/__tests__/utils.spec.ts b/packages/vite/src/node/__tests__/utils.spec.ts
index 1162105c3f19c7..29fd53f3c9a32e 100644
--- a/packages/vite/src/node/__tests__/utils.spec.ts
+++ b/packages/vite/src/node/__tests__/utils.spec.ts
@@ -4,6 +4,7 @@ import {
isWindows,
resolveHostname
} from '../utils'
+import { describe, test, expect } from 'vitest'
describe('injectQuery', () => {
if (isWindows) {
diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts
index d898b090fcdf6c..d4d4085bb829ed 100644
--- a/packages/vite/src/node/build.ts
+++ b/packages/vite/src/node/build.ts
@@ -38,14 +38,11 @@ import type { DepOptimizationMetadata } from './optimizer'
import { getDepsCacheDir, findKnownImports } from './optimizer'
import { assetImportMetaUrlPlugin } from './plugins/assetImportMetaUrl'
import { loadFallbackPlugin } from './plugins/loadFallback'
+import type { PackageData } from './packages'
import { watchPackageDataPlugin } from './packages'
+import { ensureWatchPlugin } from './plugins/ensureWatch'
export interface BuildOptions {
- /**
- * Base public path when served in production.
- * @deprecated `base` is now a root-level config option.
- */
- base?: string
/**
* Compatibility transform target. The transform is performed with esbuild
* and the lowest supported target is es2015/es6. Note this only handles
@@ -69,13 +66,6 @@ export interface BuildOptions {
* @default true
*/
polyfillModulePreload?: boolean
- /**
- * whether to inject dynamic import polyfill.
- * Note: does not apply to library mode.
- * @default false
- * @deprecated use plugin-legacy for browsers that don't support dynamic import
- */
- polyfillDynamicImport?: boolean
/**
* Directory relative from `root` where build output will be placed. If the
* directory exists, it will be removed before the build.
@@ -129,10 +119,6 @@ export interface BuildOptions {
* https://terser.org/docs/api-reference#minify-options
*/
terserOptions?: Terser.MinifyOptions
- /**
- * @deprecated Vite now uses esbuild for CSS minification.
- */
- cleanCssOptions?: any
/**
* Will be merged with internal rollup options.
* https://rollupjs.org/guide/en/#big-list-of-options
@@ -197,12 +183,6 @@ export interface BuildOptions {
* Can slightly improve build speed.
*/
reportCompressedSize?: boolean
- /**
- * Set to false to disable brotli compressed size reporting for build.
- * Can slightly improve build speed.
- * @deprecated use `build.reportCompressedSize` instead.
- */
- brotliSize?: boolean
/**
* Adjust chunk size warning limit (in kbs).
* @default 500
@@ -224,13 +204,7 @@ export interface LibraryOptions {
export type LibraryFormats = 'es' | 'cjs' | 'umd' | 'iife'
-export type ResolvedBuildOptions = Required<
- Omit<
- BuildOptions,
- // make deprecated options optional
- 'base' | 'cleanCssOptions' | 'polyfillDynamicImport' | 'brotliSize'
- >
->
+export type ResolvedBuildOptions = Required
export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
const resolved: ResolvedBuildOptions = {
@@ -252,7 +226,6 @@ export function resolveBuildOptions(raw?: BuildOptions): ResolvedBuildOptions {
ssr: false,
ssrManifest: false,
reportCompressedSize: true,
- // brotliSize: true,
chunkSizeWarningLimit: 500,
watch: null,
...raw,
@@ -308,6 +281,7 @@ export function resolveBuildPlugins(config: ResolvedConfig): {
return {
pre: [
+ ...(options.watch ? [ensureWatchPlugin()] : []),
watchPackageDataPlugin(config),
commonjsPlugin(options.commonjsOptions),
dataURIPlugin(),
@@ -319,7 +293,7 @@ export function resolveBuildPlugins(config: ResolvedConfig): {
],
post: [
buildImportAnalysisPlugin(config),
- buildEsbuildPlugin(config),
+ ...(config.esbuild !== false ? [buildEsbuildPlugin(config)] : []),
...(options.minify ? [terserPlugin(config)] : []),
...(options.manifest ? [manifestPlugin(config)] : []),
...(options.ssrManifest ? [ssrManifestPlugin(config)] : []),
@@ -449,15 +423,6 @@ async function doBuild(
try {
const buildOutputOptions = (output: OutputOptions = {}): OutputOptions => {
- // @ts-ignore
- if (output.output) {
- config.logger.warn(
- `You've set "rollupOptions.output.output" in your config. ` +
- `This is deprecated and will override all Vite.js default output options. ` +
- `Please use "rollupOptions.output" instead.`
- )
- }
-
return {
dir: outDir,
format: ssr ? 'cjs' : 'es',
@@ -599,9 +564,11 @@ function prepareOutDir(
}
}
-function getPkgName(root: string) {
- const { name } = JSON.parse(lookupFile(root, ['package.json']) || `{}`)
+function getPkgJson(root: string): PackageData['data'] {
+ return JSON.parse(lookupFile(root, ['package.json']) || `{}`)
+}
+function getPkgName(name: string) {
return name?.startsWith('@') ? name.split('/')[1] : name
}
@@ -614,14 +581,23 @@ export function resolveLibFilename(
return libOptions.fileName(format)
}
- const name = libOptions.fileName || getPkgName(root)
+ const packageJson = getPkgJson(root)
+ const name = libOptions.fileName || getPkgName(packageJson.name)
if (!name)
throw new Error(
'Name in package.json is required if option "build.lib.fileName" is not provided.'
)
- return `${name}.${format}.js`
+ let extension: string
+
+ if (packageJson?.type === 'module') {
+ extension = format === 'cjs' || format === 'umd' ? 'cjs' : 'js'
+ } else {
+ extension = format === 'es' ? 'mjs' : 'js'
+ }
+
+ return `${name}.${format}.${extension}`
}
function resolveBuildOutputs(
diff --git a/packages/vite/src/node/cli.ts b/packages/vite/src/node/cli.ts
index 9cec6ebd9cfd68..89412a825e9fc1 100644
--- a/packages/vite/src/node/cli.ts
+++ b/packages/vite/src/node/cli.ts
@@ -130,7 +130,7 @@ cli
.option('--outDir ', `[string] output directory (default: dist)`)
.option(
'--assetsDir ',
- `[string] directory under outDir to place assets in (default: _assets)`
+ `[string] directory under outDir to place assets in (default: assets)`
)
.option(
'--assetsInlineLimit ',
diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts
index 9910cbb3a8b004..e7fcaefeb2a799 100644
--- a/packages/vite/src/node/config.ts
+++ b/packages/vite/src/node/config.ts
@@ -31,7 +31,7 @@ import { createLogger } from './logger'
import type { DepOptimizationOptions } from './optimizer'
import { createFilter } from '@rollup/pluginutils'
import type { ResolvedBuildOptions } from '.'
-import { parse as parseUrl } from 'url'
+import { parse as parseUrl, pathToFileURL } from 'url'
import type { JsonOptions } from './plugins/json'
import type { PluginContainer } from './server/pluginContainer'
import { createPluginContainer } from './server/pluginContainer'
@@ -63,7 +63,7 @@ export function defineConfig(config: UserConfigExport): UserConfigExport {
return config
}
-export type PluginOption = Plugin | false | null | undefined
+export type PluginOption = Plugin | false | null | undefined | PluginOption[]
export interface UserConfig {
/**
@@ -109,7 +109,7 @@ export interface UserConfig {
/**
* Array of vite plugins to use.
*/
- plugins?: (PluginOption | PluginOption[])[]
+ plugins?: PluginOption[]
/**
* Configure resolver
*/
@@ -152,6 +152,14 @@ export interface UserConfig {
* @alpha
*/
ssr?: SSROptions
+ /**
+ * Experimental features
+ *
+ * Features under this field are addressed to be changed that might NOT follow semver.
+ * Please be careful and always pin Vite's version when using them.
+ * @experimental
+ */
+ experimental?: ExperimentalOptions
/**
* Log level.
* Default: 'info'
@@ -176,17 +184,6 @@ export interface UserConfig {
* @default 'VITE_'
*/
envPrefix?: string | string[]
- /**
- * Import aliases
- * @deprecated use `resolve.alias` instead
- */
- alias?: AliasOptions
- /**
- * Force Vite to always resolve listed dependencies to the same copy (from
- * project root).
- * @deprecated use `resolve.dedupe` instead
- */
- dedupe?: string[]
/**
* Worker bundle options
*/
@@ -199,7 +196,7 @@ export interface UserConfig {
/**
* Vite plugins that apply to worker bundle
*/
- plugins?: (PluginOption | PluginOption[])[]
+ plugins?: PluginOption[]
/**
* Rollup options to build worker bundle
*/
@@ -210,6 +207,16 @@ export interface UserConfig {
}
}
+export interface ExperimentalOptions {
+ /**
+ * Append fake `&lang.(ext)` when queries are specified, to preseve the file extension for following plugins to process.
+ *
+ * @experimental
+ * @default false
+ */
+ importGlobRestoreExtension?: boolean
+}
+
export type SSRTarget = 'node' | 'webworker'
export interface SSROptions {
@@ -235,10 +242,7 @@ export interface InlineConfig extends UserConfig {
}
export type ResolvedConfig = Readonly<
- Omit<
- UserConfig,
- 'plugins' | 'alias' | 'dedupe' | 'assetsInclude' | 'optimizeDeps' | 'worker'
- > & {
+ Omit & {
configFile: string | undefined
configFileDependencies: string[]
inlineConfig: InlineConfig
@@ -261,7 +265,7 @@ export type ResolvedConfig = Readonly<
assetsInclude: (file: string) => boolean
logger: Logger
createResolver: (options?: Partial) => ResolveFn
- optimizeDeps: Omit
+ optimizeDeps: DepOptimizationOptions
/** @internal */
packageCache: PackageCache
worker: ResolveWorkerOptions
@@ -322,7 +326,7 @@ export async function resolveConfig(
configEnv.mode = mode
// resolve plugins
- const rawUserPlugins = (config.plugins || []).flat().filter((p) => {
+ const rawUserPlugins = (config.plugins || []).flat(Infinity).filter((p) => {
if (!p) {
return false
} else if (!p.apply) {
@@ -370,12 +374,11 @@ export async function resolveConfig(
// @ts-ignore because @rollup/plugin-alias' type doesn't allow function
// replacement, but its implementation does work with function values.
clientAlias,
- config.resolve?.alias || config.alias || []
+ config.resolve?.alias || []
)
)
const resolveOptions: ResolvedConfig['resolve'] = {
- dedupe: config.dedupe,
...config.resolve,
alias: resolvedAlias
}
@@ -461,7 +464,9 @@ export async function resolveConfig(
)
: ''
- const server = resolveServerOptions(resolvedRoot, config.server)
+ const server = resolveServerOptions(resolvedRoot, config.server, logger)
+
+ const optimizeDeps = config.optimizeDeps || {}
const resolved: ResolvedConfig = {
...config,
@@ -497,11 +502,10 @@ export async function resolveConfig(
packageCache: new Map(),
createResolver,
optimizeDeps: {
- ...config.optimizeDeps,
+ ...optimizeDeps,
esbuildOptions: {
- keepNames: config.optimizeDeps?.keepNames,
preserveSymlinks: config.resolve?.preserveSymlinks,
- ...config.optimizeDeps?.esbuildOptions
+ ...optimizeDeps.esbuildOptions
}
},
worker: resolvedWorkerOptions
@@ -538,117 +542,6 @@ export async function resolveConfig(
})
}
- // TODO Deprecation warnings - remove when out of beta
-
- const logDeprecationWarning = (
- deprecatedOption: string,
- hint: string,
- error?: Error
- ) => {
- logger.warn(
- colors.yellow(
- colors.bold(
- `(!) "${deprecatedOption}" option is deprecated. ${hint}${
- error ? `\n${error.stack}` : ''
- }`
- )
- )
- )
- }
-
- if (config.build?.base) {
- logDeprecationWarning(
- 'build.base',
- '"base" is now a root-level config option.'
- )
- config.base = config.build.base
- }
- Object.defineProperty(resolvedBuildOptions, 'base', {
- enumerable: false,
- get() {
- logDeprecationWarning(
- 'build.base',
- '"base" is now a root-level config option.',
- new Error()
- )
- return resolved.base
- }
- })
-
- if (config.alias) {
- logDeprecationWarning('alias', 'Use "resolve.alias" instead.')
- }
- Object.defineProperty(resolved, 'alias', {
- enumerable: false,
- get() {
- logDeprecationWarning(
- 'alias',
- 'Use "resolve.alias" instead.',
- new Error()
- )
- return resolved.resolve.alias
- }
- })
-
- if (config.dedupe) {
- logDeprecationWarning('dedupe', 'Use "resolve.dedupe" instead.')
- }
- Object.defineProperty(resolved, 'dedupe', {
- enumerable: false,
- get() {
- logDeprecationWarning(
- 'dedupe',
- 'Use "resolve.dedupe" instead.',
- new Error()
- )
- return resolved.resolve.dedupe
- }
- })
-
- if (config.optimizeDeps?.keepNames) {
- logDeprecationWarning(
- 'optimizeDeps.keepNames',
- 'Use "optimizeDeps.esbuildOptions.keepNames" instead.'
- )
- }
- Object.defineProperty(resolved.optimizeDeps, 'keepNames', {
- enumerable: false,
- get() {
- logDeprecationWarning(
- 'optimizeDeps.keepNames',
- 'Use "optimizeDeps.esbuildOptions.keepNames" instead.',
- new Error()
- )
- return resolved.optimizeDeps.esbuildOptions?.keepNames
- }
- })
-
- if (config.build?.polyfillDynamicImport) {
- logDeprecationWarning(
- 'build.polyfillDynamicImport',
- '"polyfillDynamicImport" has been removed. Please use @vitejs/plugin-legacy if your target browsers do not support dynamic imports.'
- )
- }
-
- Object.defineProperty(resolvedBuildOptions, 'polyfillDynamicImport', {
- enumerable: false,
- get() {
- logDeprecationWarning(
- 'build.polyfillDynamicImport',
- '"polyfillDynamicImport" has been removed. Please use @vitejs/plugin-legacy if your target browsers do not support dynamic imports.',
- new Error()
- )
- return false
- }
- })
-
- if (config.build?.cleanCssOptions) {
- logDeprecationWarning(
- 'build.cleanCssOptions',
- 'Vite now uses esbuild for CSS minification.'
- )
- }
-
if (config.build?.terserOptions && config.build.minify !== 'terser') {
logger.warn(
colors.yellow(
@@ -743,7 +636,12 @@ function mergeConfigRecursively(
} else if (key === 'assetsInclude' && rootPath === '') {
merged[key] = [].concat(existing, value)
continue
- } else if (key === 'noExternal' && existing === true) {
+ } else if (
+ key === 'noExternal' &&
+ rootPath === 'ssr' &&
+ (existing === true || value === true)
+ ) {
+ merged[key] = true
continue
}
@@ -1006,7 +904,7 @@ async function bundleConfigFile(
contents: contents
.replace(
/\bimport\.meta\.url\b/g,
- JSON.stringify(`file://${args.path}`)
+ JSON.stringify(pathToFileURL(args.path).href)
)
.replace(
/\b__dirname\b/g,
diff --git a/packages/vite/src/node/importGlob.ts b/packages/vite/src/node/importGlob.ts
deleted file mode 100644
index a759bee2b5fa59..00000000000000
--- a/packages/vite/src/node/importGlob.ts
+++ /dev/null
@@ -1,263 +0,0 @@
-import path from 'path'
-import { promises as fsp } from 'fs'
-import glob from 'fast-glob'
-import JSON5 from 'json5'
-import {
- isModernFlag,
- preloadMethod,
- preloadMarker
-} from './plugins/importAnalysisBuild'
-import { isCSSRequest } from './plugins/css'
-import {
- cleanUrl,
- singlelineCommentsRE,
- multilineCommentsRE,
- blankReplacer,
- normalizePath
-} from './utils'
-import type { RollupError } from 'rollup'
-import type { Logger } from '.'
-import colors from 'picocolors'
-
-interface GlobParams {
- base: string
- pattern: string
- parentDepth: number
- isAbsolute: boolean
-}
-
-interface GlobOptions {
- as?: string
- /**
- * @deprecated
- */
- assert?: {
- type: string
- }
-}
-
-function formatGlobRelativePattern(base: string, pattern: string): GlobParams {
- let parentDepth = 0
- while (pattern.startsWith('../')) {
- pattern = pattern.slice(3)
- base = path.resolve(base, '../')
- parentDepth++
- }
- if (pattern.startsWith('./')) {
- pattern = pattern.slice(2)
- }
-
- return { base, pattern, parentDepth, isAbsolute: false }
-}
-
-export async function transformImportGlob(
- source: string,
- pos: number,
- importer: string,
- importIndex: number,
- root: string,
- logger: Logger,
- normalizeUrl?: (url: string, pos: number) => Promise<[string, string]>,
- resolve?: (url: string, importer?: string) => Promise,
- preload = true
-): Promise<{
- importsString: string
- imports: string[]
- exp: string
- endIndex: number
- isEager: boolean
- pattern: string
- base: string
-}> {
- const isEager = source.slice(pos, pos + 21) === 'import.meta.globEager'
- const isEagerDefault =
- isEager && source.slice(pos + 21, pos + 28) === 'Default'
-
- const err = (msg: string) => {
- const e = new Error(`Invalid glob import syntax: ${msg}`)
- ;(e as any).pos = pos
- return e
- }
-
- importer = cleanUrl(importer)
- const importerBasename = path.basename(importer)
-
- const [userPattern, options, endIndex] = lexGlobPattern(source, pos)
-
- let globParams: GlobParams | null = null
- if (userPattern.startsWith('/')) {
- globParams = {
- isAbsolute: true,
- base: path.resolve(root),
- pattern: userPattern.slice(1),
- parentDepth: 0
- }
- } else if (userPattern.startsWith('.')) {
- globParams = formatGlobRelativePattern(path.dirname(importer), userPattern)
- } else if (resolve) {
- const resolvedId = await resolve(userPattern, importer)
- if (resolvedId) {
- const importerDirname = path.dirname(importer)
- globParams = formatGlobRelativePattern(
- importerDirname,
- normalizePath(path.relative(importerDirname, resolvedId))
- )
- }
- }
-
- if (!globParams) {
- throw err(
- `pattern must start with "." or "/" (relative to project root) or alias path`
- )
- }
- const { base, parentDepth, isAbsolute, pattern } = globParams
-
- const files = glob.sync(pattern, {
- cwd: base,
- // Ignore node_modules by default unless explicitly indicated in the pattern
- ignore: /(^|\/)node_modules\//.test(pattern) ? [] : ['**/node_modules/**']
- })
- const imports: string[] = []
- let importsString = ``
- let entries = ``
- for (let i = 0; i < files.length; i++) {
- // skip importer itself
- if (files[i] === importerBasename) continue
- const file = isAbsolute
- ? `/${files[i]}`
- : parentDepth
- ? `${'../'.repeat(parentDepth)}${files[i]}`
- : `./${files[i]}`
- let importee = file
- if (normalizeUrl) {
- ;[importee] = await normalizeUrl(file, pos)
- }
- imports.push(importee)
- // TODO remove assert syntax for the Vite 3.0 release.
- const isRawAssert = options?.assert?.type === 'raw'
- const isRawType = options?.as === 'raw'
- if (isRawType || isRawAssert) {
- if (isRawAssert) {
- logger.warn(
- colors.yellow(
- colors.bold(
- "(!) import.meta.glob('...', { assert: { type: 'raw' }}) is deprecated. Use import.meta.glob('...', { as: 'raw' }) instead."
- )
- )
- )
- }
- entries += ` ${JSON.stringify(file)}: ${JSON.stringify(
- await fsp.readFile(path.join(base, files[i]), 'utf-8')
- )},`
- } else {
- const importeeUrl = isCSSRequest(importee) ? `${importee}?used` : importee
- if (isEager) {
- const identifier = `__glob_${importIndex}_${i}`
- // css imports injecting a ?used query to export the css string
- importsString += `import ${
- isEagerDefault ? `` : `* as `
- }${identifier} from ${JSON.stringify(importeeUrl)};`
- entries += ` ${JSON.stringify(file)}: ${identifier},`
- } else {
- let imp = `import(${JSON.stringify(importeeUrl)})`
- if (!normalizeUrl && preload) {
- imp =
- `(${isModernFlag}` +
- `? ${preloadMethod}(()=>${imp},"${preloadMarker}")` +
- `: ${imp})`
- }
- entries += ` ${JSON.stringify(file)}: () => ${imp},`
- }
- }
- }
-
- return {
- imports,
- importsString,
- exp: `{${entries}}`,
- endIndex,
- isEager,
- pattern,
- base
- }
-}
-
-const enum LexerState {
- inCall,
- inSingleQuoteString,
- inDoubleQuoteString,
- inTemplateString
-}
-
-function lexGlobPattern(
- code: string,
- pos: number
-): [string, GlobOptions, number] {
- let state = LexerState.inCall
- let pattern = ''
-
- let i = code.indexOf(`(`, pos) + 1
- outer: for (; i < code.length; i++) {
- const char = code.charAt(i)
- switch (state) {
- case LexerState.inCall:
- if (char === `'`) {
- state = LexerState.inSingleQuoteString
- } else if (char === `"`) {
- state = LexerState.inDoubleQuoteString
- } else if (char === '`') {
- state = LexerState.inTemplateString
- } else if (/\s/.test(char)) {
- continue
- } else {
- error(i)
- }
- break
- case LexerState.inSingleQuoteString:
- if (char === `'`) {
- break outer
- } else {
- pattern += char
- }
- break
- case LexerState.inDoubleQuoteString:
- if (char === `"`) {
- break outer
- } else {
- pattern += char
- }
- break
- case LexerState.inTemplateString:
- if (char === '`') {
- break outer
- } else {
- pattern += char
- }
- break
- default:
- throw new Error('unknown import.meta.glob lexer state')
- }
- }
- const noCommentCode = code
- .slice(i + 1)
- .replace(singlelineCommentsRE, blankReplacer)
- .replace(multilineCommentsRE, blankReplacer)
-
- const endIndex = noCommentCode.indexOf(')')
- const optionString = noCommentCode.substring(0, endIndex)
- const commaIndex = optionString.indexOf(',')
-
- let options = {}
- if (commaIndex > -1) {
- options = JSON5.parse(optionString.substring(commaIndex + 1))
- }
- return [pattern, options, endIndex + i + 2]
-}
-
-function error(pos: number) {
- const err = new Error(
- `import.meta.glob() can only accept string literals.`
- ) as RollupError
- err.pos = pos
- throw err
-}
diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts
index a6dcd1d2cc56bc..0fc7560eefff01 100644
--- a/packages/vite/src/node/index.ts
+++ b/packages/vite/src/node/index.ts
@@ -4,7 +4,7 @@ export { preview } from './preview'
export { build } from './build'
export { optimizeDeps } from './optimizer'
export { send } from './server/send'
-export { createLogger, printHttpServerUrls } from './logger'
+export { createLogger } from './logger'
export { formatPostcssSourceMap } from './plugins/css'
export { transformWithEsbuild } from './plugins/esbuild'
export { resolvePackageEntry } from './plugins/resolve'
@@ -33,6 +33,7 @@ export type {
export type {
PreviewOptions,
PreviewServer,
+ PreviewServerHook,
ResolvedPreviewOptions
} from './preview'
export type {
@@ -74,6 +75,9 @@ export type { TransformOptions as EsbuildTransformOptions } from 'esbuild'
export type { ESBuildOptions, ESBuildTransformResult } from './plugins/esbuild'
export type { Manifest, ManifestChunk } from './plugins/manifest'
export type { ResolveOptions, InternalResolveOptions } from './plugins/resolve'
+export type { SplitVendorChunkCache } from './plugins/splitVendorChunk'
+import type { ChunkMetadata } from './plugins/metadata'
+
export type {
WebSocketServer,
WebSocketClient,
@@ -88,6 +92,7 @@ export type {
TransformResult
} from './server/transformRequest'
export type { HmrOptions, HmrContext } from './server/hmr'
+
export type {
HMRPayload,
ConnectedPayload,
@@ -111,9 +116,12 @@ export type { RollupCommonJSOptions } from 'types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'types/dynamicImportVars'
export type { CustomEventMap, InferCustomEventPayload } from 'types/customEvent'
export type { Matcher, AnymatchPattern, AnymatchFn } from 'types/anymatch'
-export type { SplitVendorChunkCache } from './plugins/splitVendorChunk'
-
-import type { ChunkMetadata } from './plugins/metadata'
+export type {
+ ImportGlobFunction,
+ ImportGlobEagerFunction,
+ ImportGlobOptions,
+ KnownAsTypeMap
+} from 'types/importGlob'
declare module 'rollup' {
export interface RenderedChunk {
diff --git a/packages/vite/src/node/logger.ts b/packages/vite/src/node/logger.ts
index b6cf76f2aaa432..4f5784aeb527ff 100644
--- a/packages/vite/src/node/logger.ts
+++ b/packages/vite/src/node/logger.ts
@@ -144,16 +144,6 @@ export function createLogger(
return logger
}
-/**
- * @deprecated Use `server.printUrls()` instead
- */
-export function printHttpServerUrls(
- server: Server,
- config: ResolvedConfig
-): void {
- printCommonServerUrls(server, config.server, config)
-}
-
export function printCommonServerUrls(
server: Server,
options: CommonServerOptions,
@@ -190,7 +180,15 @@ function printServerUrls(
} else {
Object.values(os.networkInterfaces())
.flatMap((nInterface) => nInterface ?? [])
- .filter((detail) => detail && detail.address && detail.family === 'IPv4')
+ .filter(
+ (detail) =>
+ detail &&
+ detail.address &&
+ // Node < v18
+ ((typeof detail.family === 'string' && detail.family === 'IPv4') ||
+ // Node >= v18
+ (typeof detail.family === 'number' && detail.family === 4))
+ )
.map((detail) => {
const type = detail.address.includes('127.0.0.1')
? 'Local: '
diff --git a/packages/vite/src/node/optimizer/index.ts b/packages/vite/src/node/optimizer/index.ts
index 913640686f7765..0d22554f57c456 100644
--- a/packages/vite/src/node/optimizer/index.ts
+++ b/packages/vite/src/node/optimizer/index.ts
@@ -13,7 +13,9 @@ import {
normalizePath,
writeFile,
flattenId,
- normalizeId
+ normalizeId,
+ removeDirSync,
+ renameDir
} from '../utils'
import { esbuildDepPlugin } from './esbuildDepPlugin'
import { init, parse } from 'es-module-lexer'
@@ -77,7 +79,6 @@ export interface DepOptimizationOptions {
*
* - `external` is also omitted, use Vite's `optimizeDeps.exclude` option
* - `plugins` are merged with Vite's dep plugin
- * - `keepNames` takes precedence over the deprecated `optimizeDeps.keepNames`
*
* https://esbuild.github.io/api
*/
@@ -94,10 +95,6 @@ export interface DepOptimizationOptions {
| 'outExtension'
| 'metafile'
>
- /**
- * @deprecated use `esbuildOptions.keepNames`
- */
- keepNames?: boolean
/**
* List of file extensions that can be optimized. A corresponding esbuild
* plugin must exist to handle the specific extension.
@@ -108,6 +105,12 @@ export interface DepOptimizationOptions {
* @experimental
*/
extensions?: string[]
+ /**
+ * Disables dependencies optimizations
+ * @default false
+ * @experimental
+ */
+ disabled?: boolean
}
export interface DepOptimizationResult {
@@ -117,7 +120,7 @@ export interface DepOptimizationResult {
* the page reload will be delayed until the next rerun so we need
* to be able to discard the result
*/
- commit: () => void
+ commit: () => Promise
cancel: () => void
}
@@ -200,7 +203,7 @@ export async function optimizeDeps(
const result = await runOptimizeDeps(config, depsInfo)
- result.commit()
+ await result.commit()
return result.metadata
}
@@ -380,12 +383,12 @@ export async function runOptimizeDeps(
const processingResult: DepOptimizationResult = {
metadata,
- commit() {
+ async commit() {
// Write metadata file, delete `deps` folder and rename the `processing` folder to `deps`
// Processing is done, we can now replace the depsCacheDir with processingCacheDir
// Rewire the file paths from the temporal processing dir to the final deps cache dir
removeDirSync(depsCacheDir)
- fs.renameSync(processingCacheDir, depsCacheDir)
+ await renameDir(processingCacheDir, depsCacheDir)
},
cancel() {
removeDirSync(processingCacheDir)
@@ -428,7 +431,7 @@ export async function runOptimizeDeps(
}
const define: Record = {
- 'process.env.NODE_ENV': JSON.stringify(config.mode)
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || config.mode)
}
for (const key in config.define) {
const value = config.define[key]
@@ -514,13 +517,6 @@ export async function runOptimizeDeps(
return processingResult
}
-function removeDirSync(dir: string) {
- if (fs.existsSync(dir)) {
- const rmSync = fs.rmSync ?? fs.rmdirSync // TODO: Remove after support for Node 12 is dropped
- rmSync(dir, { recursive: true })
- }
-}
-
export async function findKnownImports(
config: ResolvedConfig
): Promise {
@@ -737,11 +733,12 @@ export async function extractExportsData(
try {
exportsData = parse(entryContent) as ExportsData
} catch {
+ const loader = esbuildOptions.loader?.[path.extname(filePath)] || 'jsx'
debug(
- `Unable to parse: ${filePath}.\n Trying again with a JSX transform.`
+ `Unable to parse: ${filePath}.\n Trying again with a ${loader} transform.`
)
const transformed = await transformWithEsbuild(entryContent, filePath, {
- loader: 'jsx'
+ loader
})
// Ensure that optimization won't fail by defaulting '.js' to the JSX parser.
// This is useful for packages such as Gatsby.
@@ -814,7 +811,7 @@ export function getDepHash(config: ResolvedConfig): string {
// only a subset of config options that can affect dep optimization
content += JSON.stringify(
{
- mode: config.mode,
+ mode: process.env.NODE_ENV || config.mode,
root: config.root,
define: config.define,
resolve: config.resolve,
diff --git a/packages/vite/src/node/optimizer/registerMissing.ts b/packages/vite/src/node/optimizer/registerMissing.ts
index 203563db6b4172..b9242a4bf8e085 100644
--- a/packages/vite/src/node/optimizer/registerMissing.ts
+++ b/packages/vite/src/node/optimizer/registerMissing.ts
@@ -207,8 +207,8 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
)
})
- const commitProcessing = () => {
- processingResult.commit()
+ const commitProcessing = async () => {
+ await processingResult.commit()
// While optimizeDeps is running, new missing deps may be discovered,
// in which case they will keep being added to metadata.discovered
@@ -258,7 +258,7 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
}
if (!needsReload) {
- commitProcessing()
+ await commitProcessing()
if (!isDebugEnabled) {
if (newDepsToLogHandle) clearTimeout(newDepsToLogHandle)
@@ -288,7 +288,7 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
}
)
} else {
- commitProcessing()
+ await commitProcessing()
if (!isDebugEnabled) {
if (newDepsToLogHandle) clearTimeout(newDepsToLogHandle)
@@ -327,7 +327,6 @@ export function createOptimizedDeps(server: ViteDevServer): OptimizedDeps {
// Reset missing deps, let the server rediscover the dependencies
metadata.discovered = {}
- fullReload()
}
currentlyProcessing = false
diff --git a/packages/vite/src/node/optimizer/scan.ts b/packages/vite/src/node/optimizer/scan.ts
index e940617386eb35..111aefc40dea15 100644
--- a/packages/vite/src/node/optimizer/scan.ts
+++ b/packages/vite/src/node/optimizer/scan.ts
@@ -1,9 +1,9 @@
import fs from 'fs'
import path from 'path'
import glob from 'fast-glob'
-import type { ResolvedConfig, Logger } from '..'
+import type { ResolvedConfig } from '..'
import type { Loader, Plugin, OnLoadResult } from 'esbuild'
-import { build, transform } from 'esbuild'
+import { build } from 'esbuild'
import {
KNOWN_ASSET_TYPES,
JS_TYPES_RE,
@@ -25,11 +25,9 @@ import {
} from '../utils'
import type { PluginContainer } from '../server/pluginContainer'
import { createPluginContainer } from '../server/pluginContainer'
-import { init, parse } from 'es-module-lexer'
-import MagicString from 'magic-string'
-import { transformImportGlob } from '../importGlob'
import { performance } from 'perf_hooks'
import colors from 'picocolors'
+import { transformGlobImport } from '../plugins/importMetaGlob'
const debug = createDebugger('vite:deps')
@@ -300,19 +298,18 @@ function esbuildScanPlugin(
(loader.startsWith('ts') ? extractImportPaths(content) : '')
const key = `${path}?id=${scriptId++}`
-
if (contents.includes('import.meta.glob')) {
scripts[key] = {
- // transformGlob already transforms to js
loader: 'js',
- contents: await transformGlob(
- contents,
- path,
- config.root,
- loader,
- resolve,
- config.logger
- )
+ contents:
+ (
+ await transformGlobImport(
+ contents,
+ path,
+ config.root,
+ resolve
+ )
+ )?.s.toString() || contents
}
} else {
scripts[key] = {
@@ -463,21 +460,12 @@ function esbuildScanPlugin(
contents = config.esbuild.jsxInject + `\n` + contents
}
- if (contents.includes('import.meta.glob')) {
- return transformGlob(
- contents,
- id,
- config.root,
- ext as Loader,
- resolve,
- config.logger
- ).then((contents) => ({
- loader: ext as Loader,
- contents
- }))
- }
+ const loader =
+ config.optimizeDeps?.esbuildOptions?.loader?.[`.${ext}`] ||
+ (ext as Loader)
+
return {
- loader: ext as Loader,
+ loader,
contents
}
})
@@ -485,43 +473,6 @@ function esbuildScanPlugin(
}
}
-async function transformGlob(
- source: string,
- importer: string,
- root: string,
- loader: Loader,
- resolve: (url: string, importer?: string) => Promise,
- logger: Logger
-) {
- // transform the content first since es-module-lexer can't handle non-js
- if (loader !== 'js') {
- source = (await transform(source, { loader })).code
- }
-
- await init
- const imports = parse(source)[0]
- const s = new MagicString(source)
- for (let index = 0; index < imports.length; index++) {
- const { s: start, e: end, ss: expStart } = imports[index]
- const url = source.slice(start, end)
- if (url !== 'import.meta') continue
- if (source.slice(end, end + 5) !== '.glob') continue
- const { importsString, exp, endIndex } = await transformImportGlob(
- source,
- start,
- normalizePath(importer),
- index,
- root,
- logger,
- undefined,
- resolve
- )
- s.prepend(importsString)
- s.overwrite(expStart, endIndex, exp, { contentOnly: true })
- }
- return s.toString()
-}
-
/**
* when using TS + (Vue + `
url in style tag
url
@@ -188,7 +235,10 @@
url
background-size: 10px 10px;
}
-
+
inline style
use style class
@@ -212,6 +262,25 @@
@import
@import CSS from publicDir should load (this should be red)
+
import module css
+
+
+
+
style in svg
+
+
@@ -268,6 +337,12 @@
document.querySelector('.import-meta-url-img-comma-nl').src =
metaUrlWithCommaNL
+ import classNames from './css/foo.module.css'
+ document.querySelector('#foo').className = classNames['foo-module']
+
+ import someString from './static/foo.txt?raw'
+ document.querySelector('.raw-query').textContent = someString
+
const metaUrlNonExistent = new URL('non-existent', import.meta.url).pathname
text('.non-existent-import-meta-url', metaUrlNonExistent)
diff --git a/packages/playground/assets/nested/asset.png b/playground/assets/nested/asset.png
similarity index 100%
rename from packages/playground/assets/nested/asset.png
rename to playground/assets/nested/asset.png
diff --git a/packages/playground/assets/nested/fragment-bg.svg b/playground/assets/nested/fragment-bg.svg
similarity index 100%
rename from packages/playground/assets/nested/fragment-bg.svg
rename to playground/assets/nested/fragment-bg.svg
diff --git a/packages/playground/assets/nested/fragment.svg b/playground/assets/nested/fragment.svg
similarity index 100%
rename from packages/playground/assets/nested/fragment.svg
rename to playground/assets/nested/fragment.svg
diff --git a/packages/playground/assets/nested/icon.png b/playground/assets/nested/icon.png
similarity index 100%
rename from packages/playground/assets/nested/icon.png
rename to playground/assets/nested/icon.png
diff --git "a/packages/playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.png" "b/playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.png"
similarity index 100%
rename from "packages/playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.png"
rename to "playground/assets/nested/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.png"
diff --git a/packages/playground/assets/package.json b/playground/assets/package.json
similarity index 72%
rename from packages/playground/assets/package.json
rename to playground/assets/package.json
index 33f64cef771525..2a1f3148e2cf07 100644
--- a/packages/playground/assets/package.json
+++ b/playground/assets/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/assets/static/foo.css b/playground/assets/static/foo.css
similarity index 100%
rename from packages/playground/assets/static/foo.css
rename to playground/assets/static/foo.css
diff --git a/playground/assets/static/foo.txt b/playground/assets/static/foo.txt
new file mode 100644
index 00000000000000..19102815663d23
--- /dev/null
+++ b/playground/assets/static/foo.txt
@@ -0,0 +1 @@
+foo
\ No newline at end of file
diff --git a/packages/playground/assets/static/icon.png b/playground/assets/static/icon.png
similarity index 100%
rename from packages/playground/assets/static/icon.png
rename to playground/assets/static/icon.png
diff --git a/packages/playground/assets/static/import-expression.js b/playground/assets/static/import-expression.js
similarity index 100%
rename from packages/playground/assets/static/import-expression.js
rename to playground/assets/static/import-expression.js
diff --git a/packages/playground/assets/static/raw.css b/playground/assets/static/raw.css
similarity index 100%
rename from packages/playground/assets/static/raw.css
rename to playground/assets/static/raw.css
diff --git a/packages/playground/assets/static/raw.js b/playground/assets/static/raw.js
similarity index 100%
rename from packages/playground/assets/static/raw.js
rename to playground/assets/static/raw.js
diff --git a/packages/playground/assets/vite.config.js b/playground/assets/vite.config.js
similarity index 100%
rename from packages/playground/assets/vite.config.js
rename to playground/assets/vite.config.js
diff --git "a/packages/playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.js" "b/playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.js"
similarity index 100%
rename from "packages/playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.js"
rename to "playground/assets/\343\203\206\343\202\271\343\203\210-\346\270\254\350\251\246-white space.js"
diff --git a/packages/playground/backend-integration/__tests__/backend-integration.spec.ts b/playground/backend-integration/__tests__/backend-integration.spec.ts
similarity index 92%
rename from packages/playground/backend-integration/__tests__/backend-integration.spec.ts
rename to playground/backend-integration/__tests__/backend-integration.spec.ts
index 3e189972f4baed..7eebc9c27ff05a 100644
--- a/packages/playground/backend-integration/__tests__/backend-integration.spec.ts
+++ b/playground/backend-integration/__tests__/backend-integration.spec.ts
@@ -32,6 +32,12 @@ if (isBuild) {
expect(htmlEntry.assets.length).toEqual(1)
})
} else {
+ test('No ReferenceError', async () => {
+ browserErrors.forEach((error) => {
+ expect(error.name).not.toBe('ReferenceError')
+ })
+ })
+
describe('CSS HMR', () => {
test('preserve the base in CSS HMR', async () => {
await untilUpdated(() => getColor('body'), 'black') // sanity check
diff --git a/packages/playground/backend-integration/frontend/entrypoints/global.css b/playground/backend-integration/frontend/entrypoints/global.css
similarity index 100%
rename from packages/playground/backend-integration/frontend/entrypoints/global.css
rename to playground/backend-integration/frontend/entrypoints/global.css
diff --git a/packages/playground/backend-integration/frontend/entrypoints/index.html b/playground/backend-integration/frontend/entrypoints/index.html
similarity index 100%
rename from packages/playground/backend-integration/frontend/entrypoints/index.html
rename to playground/backend-integration/frontend/entrypoints/index.html
diff --git a/packages/playground/backend-integration/frontend/entrypoints/main.ts b/playground/backend-integration/frontend/entrypoints/main.ts
similarity index 83%
rename from packages/playground/backend-integration/frontend/entrypoints/main.ts
rename to playground/backend-integration/frontend/entrypoints/main.ts
index b95a989ada81c2..f5a332191dd9e4 100644
--- a/packages/playground/backend-integration/frontend/entrypoints/main.ts
+++ b/playground/backend-integration/frontend/entrypoints/main.ts
@@ -1,3 +1,5 @@
+import 'vite/modulepreload-polyfill'
+
export const colorClass = 'text-black'
export function colorHeading() {
diff --git a/packages/playground/backend-integration/frontend/images/logo.png b/playground/backend-integration/frontend/images/logo.png
similarity index 100%
rename from packages/playground/backend-integration/frontend/images/logo.png
rename to playground/backend-integration/frontend/images/logo.png
diff --git a/packages/playground/backend-integration/frontend/styles/background.css b/playground/backend-integration/frontend/styles/background.css
similarity index 100%
rename from packages/playground/backend-integration/frontend/styles/background.css
rename to playground/backend-integration/frontend/styles/background.css
diff --git a/packages/playground/backend-integration/frontend/styles/tailwind.css b/playground/backend-integration/frontend/styles/tailwind.css
similarity index 100%
rename from packages/playground/backend-integration/frontend/styles/tailwind.css
rename to playground/backend-integration/frontend/styles/tailwind.css
diff --git a/packages/playground/backend-integration/package.json b/playground/backend-integration/package.json
similarity index 81%
rename from packages/playground/backend-integration/package.json
rename to playground/backend-integration/package.json
index b3d9b064db16e2..c1419548cb3bd3 100644
--- a/packages/playground/backend-integration/package.json
+++ b/playground/backend-integration/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"dependencies": {
diff --git a/packages/playground/backend-integration/postcss.config.js b/playground/backend-integration/postcss.config.js
similarity index 100%
rename from packages/playground/backend-integration/postcss.config.js
rename to playground/backend-integration/postcss.config.js
diff --git a/packages/playground/backend-integration/references.css b/playground/backend-integration/references.css
similarity index 100%
rename from packages/playground/backend-integration/references.css
rename to playground/backend-integration/references.css
diff --git a/packages/playground/backend-integration/tailwind.config.js b/playground/backend-integration/tailwind.config.js
similarity index 100%
rename from packages/playground/backend-integration/tailwind.config.js
rename to playground/backend-integration/tailwind.config.js
diff --git a/packages/playground/backend-integration/vite.config.js b/playground/backend-integration/vite.config.js
similarity index 100%
rename from packages/playground/backend-integration/vite.config.js
rename to playground/backend-integration/vite.config.js
diff --git a/packages/playground/cli-module/__tests__/cli-module.spec.ts b/playground/cli-module/__tests__/cli-module.spec.ts
similarity index 100%
rename from packages/playground/cli-module/__tests__/cli-module.spec.ts
rename to playground/cli-module/__tests__/cli-module.spec.ts
diff --git a/packages/playground/cli-module/__tests__/serve.js b/playground/cli-module/__tests__/serve.js
similarity index 97%
rename from packages/playground/cli-module/__tests__/serve.js
rename to playground/cli-module/__tests__/serve.js
index 2b354f566524bf..cf873fd481830b 100644
--- a/packages/playground/cli-module/__tests__/serve.js
+++ b/playground/cli-module/__tests__/serve.js
@@ -5,10 +5,10 @@
const path = require('path')
// eslint-disable-next-line node/no-restricted-require
const execa = require('execa')
-const { workspaceRoot } = require('../../testUtils')
+const { workspaceRoot, ports } = require('../../testUtils')
const isWindows = process.platform === 'win32'
-const port = (exports.port = 9511) // make sure this port is unique across tests with custom servers
+const port = (exports.port = ports['cli-module'])
const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js')
/**
diff --git a/packages/playground/cli-module/index.html b/playground/cli-module/index.html
similarity index 100%
rename from packages/playground/cli-module/index.html
rename to playground/cli-module/index.html
diff --git a/packages/playground/cli-module/index.js b/playground/cli-module/index.js
similarity index 100%
rename from packages/playground/cli-module/index.js
rename to playground/cli-module/index.js
diff --git a/packages/playground/cli-module/package.json b/playground/cli-module/package.json
similarity index 74%
rename from packages/playground/cli-module/package.json
rename to playground/cli-module/package.json
index a6d890d5a06ecb..0f297d4e4d0563 100644
--- a/packages/playground/cli-module/package.json
+++ b/playground/cli-module/package.json
@@ -6,7 +6,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"serve": "vite preview"
}
}
diff --git a/packages/playground/cli-module/vite.config.js b/playground/cli-module/vite.config.js
similarity index 100%
rename from packages/playground/cli-module/vite.config.js
rename to playground/cli-module/vite.config.js
diff --git a/packages/playground/cli/__tests__/cli.spec.ts b/playground/cli/__tests__/cli.spec.ts
similarity index 100%
rename from packages/playground/cli/__tests__/cli.spec.ts
rename to playground/cli/__tests__/cli.spec.ts
diff --git a/packages/playground/cli/__tests__/serve.js b/playground/cli/__tests__/serve.js
similarity index 97%
rename from packages/playground/cli/__tests__/serve.js
rename to playground/cli/__tests__/serve.js
index 5dd058f4e1a83c..3ad375d9d1f543 100644
--- a/packages/playground/cli/__tests__/serve.js
+++ b/playground/cli/__tests__/serve.js
@@ -5,10 +5,10 @@
const path = require('path')
// eslint-disable-next-line node/no-restricted-require
const execa = require('execa')
-const { workspaceRoot } = require('../../testUtils')
+const { workspaceRoot, ports } = require('../../testUtils')
const isWindows = process.platform === 'win32'
-const port = (exports.port = 9510) // make sure this port is unique across tests with custom servers
+const port = (exports.port = ports.cli)
const viteBin = path.join(workspaceRoot, 'packages', 'vite', 'bin', 'vite.js')
/**
diff --git a/packages/playground/cli/index.html b/playground/cli/index.html
similarity index 100%
rename from packages/playground/cli/index.html
rename to playground/cli/index.html
diff --git a/packages/playground/cli/index.js b/playground/cli/index.js
similarity index 100%
rename from packages/playground/cli/index.js
rename to playground/cli/index.js
diff --git a/packages/playground/cli/package.json b/playground/cli/package.json
similarity index 71%
rename from packages/playground/cli/package.json
rename to playground/cli/package.json
index bc1775ff722f2a..d2f8476d409c2e 100644
--- a/packages/playground/cli/package.json
+++ b/playground/cli/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/cli/vite.config.js b/playground/cli/vite.config.js
similarity index 100%
rename from packages/playground/cli/vite.config.js
rename to playground/cli/vite.config.js
diff --git a/packages/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts b/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts
similarity index 100%
rename from packages/playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts
rename to playground/css-codesplit-cjs/__tests__/css-codesplit.spec.ts
diff --git a/packages/playground/css-codesplit-cjs/index.html b/playground/css-codesplit-cjs/index.html
similarity index 100%
rename from packages/playground/css-codesplit-cjs/index.html
rename to playground/css-codesplit-cjs/index.html
diff --git a/packages/playground/css-codesplit-cjs/main.css b/playground/css-codesplit-cjs/main.css
similarity index 100%
rename from packages/playground/css-codesplit-cjs/main.css
rename to playground/css-codesplit-cjs/main.css
diff --git a/packages/playground/css-codesplit-cjs/main.js b/playground/css-codesplit-cjs/main.js
similarity index 100%
rename from packages/playground/css-codesplit-cjs/main.js
rename to playground/css-codesplit-cjs/main.js
diff --git a/packages/playground/css-codesplit-cjs/other.js b/playground/css-codesplit-cjs/other.js
similarity index 100%
rename from packages/playground/css-codesplit-cjs/other.js
rename to playground/css-codesplit-cjs/other.js
diff --git a/packages/playground/css-codesplit-cjs/package.json b/playground/css-codesplit-cjs/package.json
similarity index 73%
rename from packages/playground/css-codesplit-cjs/package.json
rename to playground/css-codesplit-cjs/package.json
index 91b848aae892aa..3504b18053b39b 100644
--- a/packages/playground/css-codesplit-cjs/package.json
+++ b/playground/css-codesplit-cjs/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/css-codesplit-cjs/style.css b/playground/css-codesplit-cjs/style.css
similarity index 100%
rename from packages/playground/css-codesplit-cjs/style.css
rename to playground/css-codesplit-cjs/style.css
diff --git a/packages/playground/css-codesplit-cjs/vite.config.js b/playground/css-codesplit-cjs/vite.config.js
similarity index 100%
rename from packages/playground/css-codesplit-cjs/vite.config.js
rename to playground/css-codesplit-cjs/vite.config.js
diff --git a/packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts b/playground/css-codesplit/__tests__/css-codesplit.spec.ts
similarity index 52%
rename from packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts
rename to playground/css-codesplit/__tests__/css-codesplit.spec.ts
index 95fe97a1b953ba..789adba23ae021 100644
--- a/packages/playground/css-codesplit/__tests__/css-codesplit.spec.ts
+++ b/playground/css-codesplit/__tests__/css-codesplit.spec.ts
@@ -1,8 +1,23 @@
import { findAssetFile, getColor, isBuild, readManifest } from '../../testUtils'
-test('should load both stylesheets', async () => {
+test('should load all stylesheets', async () => {
expect(await getColor('h1')).toBe('red')
expect(await getColor('h2')).toBe('blue')
+ expect(await getColor('.dynamic')).toBe('green')
+})
+
+test('should load dynamic import with inline', async () => {
+ const css = await page.textContent('.dynamic-inline')
+ expect(css).toMatch('.inline')
+
+ expect(await getColor('.inline')).not.toBe('yellow')
+})
+
+test('should load dynamic import with module', async () => {
+ const css = await page.textContent('.dynamic-module')
+ expect(css).toMatch('_mod_')
+
+ expect(await getColor('.mod')).toBe('yellow')
})
if (isBuild) {
@@ -10,6 +25,7 @@ if (isBuild) {
expect(findAssetFile(/style.*\.js$/)).toBe('')
expect(findAssetFile('main.*.js$')).toMatch(`/* empty css`)
expect(findAssetFile('other.*.js$')).toMatch(`/* empty css`)
+ expect(findAssetFile(/async.*\.js$/)).toBe('')
})
test('should generate correct manifest', async () => {
diff --git a/playground/css-codesplit/async.css b/playground/css-codesplit/async.css
new file mode 100644
index 00000000000000..4902b2e7bee811
--- /dev/null
+++ b/playground/css-codesplit/async.css
@@ -0,0 +1,3 @@
+.dynamic {
+ color: green;
+}
diff --git a/playground/css-codesplit/index.html b/playground/css-codesplit/index.html
new file mode 100644
index 00000000000000..63bdb59e11dc6b
--- /dev/null
+++ b/playground/css-codesplit/index.html
@@ -0,0 +1,11 @@
+
This should be red
+
This should be blue
+
+
This should be green
+
This should not be yellow
+
+
This should be yellow
+
+
+
+
diff --git a/playground/css-codesplit/inline.css b/playground/css-codesplit/inline.css
new file mode 100644
index 00000000000000..b2a2b5f1ead51f
--- /dev/null
+++ b/playground/css-codesplit/inline.css
@@ -0,0 +1,3 @@
+.inline {
+ color: yellow;
+}
diff --git a/packages/playground/css-codesplit/main.css b/playground/css-codesplit/main.css
similarity index 100%
rename from packages/playground/css-codesplit/main.css
rename to playground/css-codesplit/main.css
diff --git a/playground/css-codesplit/main.js b/playground/css-codesplit/main.js
new file mode 100644
index 00000000000000..eb6e703f79e718
--- /dev/null
+++ b/playground/css-codesplit/main.js
@@ -0,0 +1,15 @@
+import './style.css'
+import './main.css'
+
+import('./async.css')
+
+import('./inline.css?inline').then((css) => {
+ document.querySelector('.dynamic-inline').textContent = css.default
+})
+
+import('./mod.module.css').then((css) => {
+ document.querySelector('.dynamic-module').textContent = JSON.stringify(
+ css.default
+ )
+ document.querySelector('.mod').classList.add(css.default.mod)
+})
diff --git a/playground/css-codesplit/mod.module.css b/playground/css-codesplit/mod.module.css
new file mode 100644
index 00000000000000..7f84410485a32c
--- /dev/null
+++ b/playground/css-codesplit/mod.module.css
@@ -0,0 +1,3 @@
+.mod {
+ color: yellow;
+}
diff --git a/packages/playground/css-codesplit/other.js b/playground/css-codesplit/other.js
similarity index 100%
rename from packages/playground/css-codesplit/other.js
rename to playground/css-codesplit/other.js
diff --git a/packages/playground/css-codesplit/package.json b/playground/css-codesplit/package.json
similarity index 72%
rename from packages/playground/css-codesplit/package.json
rename to playground/css-codesplit/package.json
index a4403ab0e47a2a..b6fe27f6d35759 100644
--- a/packages/playground/css-codesplit/package.json
+++ b/playground/css-codesplit/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/css-codesplit/style.css b/playground/css-codesplit/style.css
similarity index 100%
rename from packages/playground/css-codesplit/style.css
rename to playground/css-codesplit/style.css
diff --git a/packages/playground/css-codesplit/vite.config.js b/playground/css-codesplit/vite.config.js
similarity index 100%
rename from packages/playground/css-codesplit/vite.config.js
rename to playground/css-codesplit/vite.config.js
diff --git a/packages/playground/css-sourcemap/__tests__/build.spec.ts b/playground/css-sourcemap/__tests__/build.spec.ts
similarity index 100%
rename from packages/playground/css-sourcemap/__tests__/build.spec.ts
rename to playground/css-sourcemap/__tests__/build.spec.ts
diff --git a/packages/playground/css-sourcemap/__tests__/serve.spec.ts b/playground/css-sourcemap/__tests__/serve.spec.ts
similarity index 72%
rename from packages/playground/css-sourcemap/__tests__/serve.spec.ts
rename to playground/css-sourcemap/__tests__/serve.spec.ts
index 11e33a78af8424..becd792e82293a 100644
--- a/packages/playground/css-sourcemap/__tests__/serve.spec.ts
+++ b/playground/css-sourcemap/__tests__/serve.spec.ts
@@ -17,68 +17,6 @@ if (!isBuild) {
throw new Error('Not found')
}
- test('inline css', async () => {
- const css = await getStyleTagContentIncluding('.inline ')
- const map = extractSourcemap(css)
- expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(`
- Object {
- "mappings": "AAGO;AACP,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,CAAC,CAAC;AACf,CAAC,CAAC,CAAC;",
- "sources": Array [
- "/root/index.html",
- ],
- "sourcesContent": Array [
- "
-
-
-
-
-
-
CSS Sourcemap
-
-
<inline>
-
-
<linked>: no import
-
<linked>: with import
-
-
<imported>: no import
-
<imported>: with import
-
-
<imported sass>
-
<imported sass> with module
-
-
<imported less> with string additionalData
-
-
<imported stylus>
-
-
-
-
-
- ",
- ],
- "version": 3,
- }
- `)
- })
-
test('linked css', async () => {
const res = await page.request.get(
new URL('./linked.css', page.url()).href,
diff --git a/packages/playground/css-sourcemap/be-imported.css b/playground/css-sourcemap/be-imported.css
similarity index 100%
rename from packages/playground/css-sourcemap/be-imported.css
rename to playground/css-sourcemap/be-imported.css
diff --git a/packages/playground/css-sourcemap/imported-with-import.css b/playground/css-sourcemap/imported-with-import.css
similarity index 100%
rename from packages/playground/css-sourcemap/imported-with-import.css
rename to playground/css-sourcemap/imported-with-import.css
diff --git a/packages/playground/css-sourcemap/imported.css b/playground/css-sourcemap/imported.css
similarity index 100%
rename from packages/playground/css-sourcemap/imported.css
rename to playground/css-sourcemap/imported.css
diff --git a/packages/playground/css-sourcemap/imported.less b/playground/css-sourcemap/imported.less
similarity index 100%
rename from packages/playground/css-sourcemap/imported.less
rename to playground/css-sourcemap/imported.less
diff --git a/packages/playground/css-sourcemap/imported.module.sass b/playground/css-sourcemap/imported.module.sass
similarity index 100%
rename from packages/playground/css-sourcemap/imported.module.sass
rename to playground/css-sourcemap/imported.module.sass
diff --git a/packages/playground/css-sourcemap/imported.sass b/playground/css-sourcemap/imported.sass
similarity index 100%
rename from packages/playground/css-sourcemap/imported.sass
rename to playground/css-sourcemap/imported.sass
diff --git a/packages/playground/css-sourcemap/imported.styl b/playground/css-sourcemap/imported.styl
similarity index 100%
rename from packages/playground/css-sourcemap/imported.styl
rename to playground/css-sourcemap/imported.styl
diff --git a/packages/playground/css-sourcemap/index.html b/playground/css-sourcemap/index.html
similarity index 100%
rename from packages/playground/css-sourcemap/index.html
rename to playground/css-sourcemap/index.html
diff --git a/packages/playground/css-sourcemap/linked-with-import.css b/playground/css-sourcemap/linked-with-import.css
similarity index 100%
rename from packages/playground/css-sourcemap/linked-with-import.css
rename to playground/css-sourcemap/linked-with-import.css
diff --git a/packages/playground/css-sourcemap/linked.css b/playground/css-sourcemap/linked.css
similarity index 100%
rename from packages/playground/css-sourcemap/linked.css
rename to playground/css-sourcemap/linked.css
diff --git a/packages/playground/css-sourcemap/package.json b/playground/css-sourcemap/package.json
similarity index 67%
rename from packages/playground/css-sourcemap/package.json
rename to playground/css-sourcemap/package.json
index c7e9e61372cefa..6c0212efa74155 100644
--- a/packages/playground/css-sourcemap/package.json
+++ b/playground/css-sourcemap/package.json
@@ -5,13 +5,13 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"devDependencies": {
"less": "^4.1.2",
- "magic-string": "^0.25.7",
- "sass": "^1.43.4",
+ "magic-string": "^0.25.9",
+ "sass": "^1.51.0",
"stylus": "^0.55.0"
}
}
diff --git a/packages/playground/css-sourcemap/vite.config.js b/playground/css-sourcemap/vite.config.js
similarity index 100%
rename from packages/playground/css-sourcemap/vite.config.js
rename to playground/css-sourcemap/vite.config.js
diff --git a/packages/playground/css/__tests__/css.spec.ts b/playground/css/__tests__/css.spec.ts
similarity index 91%
rename from packages/playground/css/__tests__/css.spec.ts
rename to playground/css/__tests__/css.spec.ts
index 3fe4a09bcc94c8..e666ca40517d57 100644
--- a/packages/playground/css/__tests__/css.spec.ts
+++ b/playground/css/__tests__/css.spec.ts
@@ -15,7 +15,11 @@ import {
// in later assertions to ensure CSS HMR doesn't reload the page
test('imported css', async () => {
const css = await page.textContent('.imported-css')
- expect(css).toContain('.imported {')
+ expect(css).toMatch(/\.imported ?{/)
+ if (isBuild) {
+ expect(css.trim()).not.toContain('\n') // check minified
+ }
+
const glob = await page.textContent('.imported-css-glob')
expect(glob).toContain('.dir-import')
const globEager = await page.textContent('.imported-css-globEager')
@@ -242,6 +246,20 @@ test('css modules w/ sass', async () => {
await untilUpdated(() => getColor(imported), 'blue')
})
+test('inline css modules', async () => {
+ const css = await page.textContent('.modules-inline')
+ expect(css).toMatch(/\.inline-module__apply-color-inline___[\w-]{5}/)
+})
+
+if (isBuild) {
+ test('@charset hoist', async () => {
+ serverLogs.forEach((log) => {
+ // no warning from esbuild css minifier
+ expect(log).not.toMatch('"@charset" must be the first rule in the file')
+ })
+ })
+}
+
test('@import dependency w/ style entry', async () => {
expect(await getColor('.css-dep')).toBe('purple')
})
@@ -324,7 +342,7 @@ test('PostCSS dir-dependency', async () => {
}
})
-test('Url separation', async () => {
+test('URL separation', async () => {
const urlSeparated = await page.$('.url-separated')
const baseUrl = 'url(images/dog.webp)'
const cases = new Array(5)
@@ -358,6 +376,10 @@ test('inlined-code', async () => {
// should resolve assets
expect(code).toContain('background:')
expect(code).not.toContain('__VITE_ASSET__')
+
+ if (isBuild) {
+ expect(code.trim()).not.toContain('\n') // check minified
+ }
})
test('minify css', async () => {
@@ -383,3 +405,21 @@ test('import css in less', async () => {
expect(await getColor('.css-in-less')).toBe('yellow')
expect(await getColor('.css-in-less-2')).toBe('blue')
})
+
+test("relative path rewritten in Less's data-uri", async () => {
+ // relative path passed to Less's data-uri is rewritten to absolute,
+ // the Less inlines it
+ expect(await getBg('.form-box-data-uri')).toMatch(
+ /^url\("data:image\/svg\+xml,%3Csvg/
+ )
+})
+
+test('PostCSS source.input.from includes query', async () => {
+ const code = await page.textContent('.postcss-source-input')
+ // should resolve assets
+ expect(code).toContain(
+ isBuild
+ ? '/postcss-source-input.css?used&query=foo'
+ : '/postcss-source-input.css?query=foo'
+ )
+})
diff --git a/packages/playground/css/__tests__/postcss-plugins-different-dir.spec.ts b/playground/css/__tests__/postcss-plugins-different-dir.spec.ts
similarity index 86%
rename from packages/playground/css/__tests__/postcss-plugins-different-dir.spec.ts
rename to playground/css/__tests__/postcss-plugins-different-dir.spec.ts
index 19e9a43ae4ff6e..8bedc26ee354c8 100644
--- a/packages/playground/css/__tests__/postcss-plugins-different-dir.spec.ts
+++ b/playground/css/__tests__/postcss-plugins-different-dir.spec.ts
@@ -1,10 +1,10 @@
-import { getColor, getBgColor } from '../../testUtils'
+import { getColor, getBgColor, ports } from '../../testUtils'
import { createServer } from 'vite'
import path from 'path'
// Regression test for https://github.com/vitejs/vite/issues/4000
test('postcss plugins in different dir', async () => {
- const port = 5006
+ const port = ports['css/postcss-plugins-different-dir']
const server = await createServer({
root: path.join(__dirname, '..', '..', 'tailwind'),
logLevel: 'silent',
diff --git a/packages/playground/css/async-treeshaken.css b/playground/css/async-treeshaken.css
similarity index 100%
rename from packages/playground/css/async-treeshaken.css
rename to playground/css/async-treeshaken.css
diff --git a/packages/playground/css/async-treeshaken.js b/playground/css/async-treeshaken.js
similarity index 100%
rename from packages/playground/css/async-treeshaken.js
rename to playground/css/async-treeshaken.js
diff --git a/packages/playground/css/async.css b/playground/css/async.css
similarity index 100%
rename from packages/playground/css/async.css
rename to playground/css/async.css
diff --git a/packages/playground/css/async.js b/playground/css/async.js
similarity index 100%
rename from packages/playground/css/async.js
rename to playground/css/async.js
diff --git a/playground/css/charset.css b/playground/css/charset.css
new file mode 100644
index 00000000000000..5c42b279f8404c
--- /dev/null
+++ b/playground/css/charset.css
@@ -0,0 +1,5 @@
+@charset "utf-8";
+
+.utf8 {
+ color: green;
+}
diff --git a/packages/playground/css/composed.module.css b/playground/css/composed.module.css
similarity index 100%
rename from packages/playground/css/composed.module.css
rename to playground/css/composed.module.css
diff --git a/packages/playground/css/composed.module.less b/playground/css/composed.module.less
similarity index 100%
rename from packages/playground/css/composed.module.less
rename to playground/css/composed.module.less
diff --git a/packages/playground/css/composed.module.scss b/playground/css/composed.module.scss
similarity index 100%
rename from packages/playground/css/composed.module.scss
rename to playground/css/composed.module.scss
diff --git a/packages/playground/css/composes-path-resolving.module.css b/playground/css/composes-path-resolving.module.css
similarity index 100%
rename from packages/playground/css/composes-path-resolving.module.css
rename to playground/css/composes-path-resolving.module.css
diff --git a/packages/playground/css/css-dep/index.css b/playground/css/css-dep/index.css
similarity index 100%
rename from packages/playground/css/css-dep/index.css
rename to playground/css/css-dep/index.css
diff --git a/packages/playground/css/css-dep/index.js b/playground/css/css-dep/index.js
similarity index 100%
rename from packages/playground/css/css-dep/index.js
rename to playground/css/css-dep/index.js
diff --git a/packages/playground/css/css-dep/index.scss b/playground/css/css-dep/index.scss
similarity index 100%
rename from packages/playground/css/css-dep/index.scss
rename to playground/css/css-dep/index.scss
diff --git a/packages/playground/css/css-dep/index.styl b/playground/css/css-dep/index.styl
similarity index 100%
rename from packages/playground/css/css-dep/index.styl
rename to playground/css/css-dep/index.styl
diff --git a/packages/playground/css/css-dep/package.json b/playground/css/css-dep/package.json
similarity index 100%
rename from packages/playground/css/css-dep/package.json
rename to playground/css/css-dep/package.json
diff --git a/packages/playground/css/dep.css b/playground/css/dep.css
similarity index 100%
rename from packages/playground/css/dep.css
rename to playground/css/dep.css
diff --git a/packages/playground/css/folder with space/ok.png b/playground/css/folder with space/ok.png
similarity index 100%
rename from packages/playground/css/folder with space/ok.png
rename to playground/css/folder with space/ok.png
diff --git a/packages/playground/css/folder with space/space.css b/playground/css/folder with space/space.css
similarity index 100%
rename from packages/playground/css/folder with space/space.css
rename to playground/css/folder with space/space.css
diff --git a/packages/playground/css/glob-dep.css b/playground/css/glob-dep.css
similarity index 100%
rename from packages/playground/css/glob-dep.css
rename to playground/css/glob-dep.css
diff --git a/packages/playground/css/glob-dep/bar.css b/playground/css/glob-dep/bar.css
similarity index 100%
rename from packages/playground/css/glob-dep/bar.css
rename to playground/css/glob-dep/bar.css
diff --git a/packages/playground/css/glob-dep/foo.css b/playground/css/glob-dep/foo.css
similarity index 100%
rename from packages/playground/css/glob-dep/foo.css
rename to playground/css/glob-dep/foo.css
diff --git a/packages/playground/css/glob-import/bar.css b/playground/css/glob-import/bar.css
similarity index 100%
rename from packages/playground/css/glob-import/bar.css
rename to playground/css/glob-import/bar.css
diff --git a/packages/playground/css/glob-import/foo.css b/playground/css/glob-import/foo.css
similarity index 100%
rename from packages/playground/css/glob-import/foo.css
rename to playground/css/glob-import/foo.css
diff --git a/packages/playground/css/imported-at-import.css b/playground/css/imported-at-import.css
similarity index 100%
rename from packages/playground/css/imported-at-import.css
rename to playground/css/imported-at-import.css
diff --git a/packages/playground/css/imported.css b/playground/css/imported.css
similarity index 100%
rename from packages/playground/css/imported.css
rename to playground/css/imported.css
diff --git a/packages/playground/css/index.html b/playground/css/index.html
similarity index 91%
rename from packages/playground/css/index.html
rename to playground/css/index.html
index 060aed7fb1b27f..15e81192cec7f1 100644
--- a/packages/playground/css/index.html
+++ b/playground/css/index.html
@@ -49,6 +49,10 @@
CSS
Imported Less string:
+
+ tests Less's `data-uri()` function with relative image paths
+
+
Stylus: This should be blue
Stylus additionalData: This should be orange
@@ -89,6 +93,12 @@
CSS
+
Inline CSS module:
+
+
+
CSS with @charset:
+
+
@import dependency w/ style enrtrypoints: this should be purple
@@ -105,7 +115,7 @@
CSS
- Url separation preservation: should have valid background-image
+ URL separation preservation: should have valid background-image
Inlined import - this should NOT be red.
@@ -125,6 +135,9 @@
CSS
Raw Support
+
+
PostCSS source.input.from. Should include query
+
diff --git a/playground/css/inline.module.css b/playground/css/inline.module.css
new file mode 100644
index 00000000000000..9566e21e2cd1af
--- /dev/null
+++ b/playground/css/inline.module.css
@@ -0,0 +1,3 @@
+.apply-color-inline {
+ color: turquoise;
+}
diff --git a/packages/playground/css/inlined.css b/playground/css/inlined.css
similarity index 100%
rename from packages/playground/css/inlined.css
rename to playground/css/inlined.css
diff --git a/packages/playground/css/less.less b/playground/css/less.less
similarity index 55%
rename from packages/playground/css/less.less
rename to playground/css/less.less
index 69ffa830862014..49cbd3c3bb336e 100644
--- a/packages/playground/css/less.less
+++ b/playground/css/less.less
@@ -1,6 +1,9 @@
@import '@/nested/nested';
@import './nested/css-in-less.less';
+// Test data-uri calls with relative images.
+@import './less/components/form.less';
+
@color: blue;
.less {
diff --git a/playground/css/less/components/form.less b/playground/css/less/components/form.less
new file mode 100644
index 00000000000000..feaaea94ce1bba
--- /dev/null
+++ b/playground/css/less/components/form.less
@@ -0,0 +1,4 @@
+.form-box-data-uri {
+ // data-uri() calls with relative paths should be replaced just like urls.
+ background-image: data-uri('../images/backgrounds/form-select.svg');
+}
diff --git a/playground/css/less/images/backgrounds/form-select.svg b/playground/css/less/images/backgrounds/form-select.svg
new file mode 100644
index 00000000000000..8aaf69c09e03f4
--- /dev/null
+++ b/playground/css/less/images/backgrounds/form-select.svg
@@ -0,0 +1,4 @@
+
diff --git a/packages/playground/css/linked-at-import.css b/playground/css/linked-at-import.css
similarity index 100%
rename from packages/playground/css/linked-at-import.css
rename to playground/css/linked-at-import.css
diff --git a/packages/playground/css/linked.css b/playground/css/linked.css
similarity index 100%
rename from packages/playground/css/linked.css
rename to playground/css/linked.css
diff --git a/packages/playground/css/main.js b/playground/css/main.js
similarity index 83%
rename from packages/playground/css/main.js
rename to playground/css/main.js
index 6edd840a87c5e7..90f74c96793c55 100644
--- a/packages/playground/css/main.js
+++ b/playground/css/main.js
@@ -38,6 +38,12 @@ text(
JSON.stringify(composesPathResolvingMod, null, 2)
)
+import inlineMod from './inline.module.css?inline'
+text('.modules-inline', inlineMod)
+
+import charset from './charset.css'
+text('.charset-css', charset)
+
import './dep.css'
import './glob-dep.css'
@@ -74,10 +80,15 @@ text('.inlined-code', inlined)
// glob
const glob = import.meta.glob('./glob-import/*.css')
-Promise.all(Object.keys(glob).map((key) => glob[key]())).then((res) => {
+Promise.all(
+ Object.keys(glob).map((key) => glob[key]().then((i) => i.default))
+).then((res) => {
text('.imported-css-glob', JSON.stringify(res, null, 2))
})
// globEager
-const globEager = import.meta.globEager('./glob-import/*.css')
+const globEager = import.meta.glob('./glob-import/*.css', { eager: true })
text('.imported-css-globEager', JSON.stringify(globEager, null, 2))
+
+import postcssSourceInput from './postcss-source-input.css?query=foo'
+text('.postcss-source-input', postcssSourceInput)
diff --git a/packages/playground/css/minify.css b/playground/css/minify.css
similarity index 100%
rename from packages/playground/css/minify.css
rename to playground/css/minify.css
diff --git a/packages/playground/css/mod.module.css b/playground/css/mod.module.css
similarity index 100%
rename from packages/playground/css/mod.module.css
rename to playground/css/mod.module.css
diff --git a/packages/playground/css/mod.module.scss b/playground/css/mod.module.scss
similarity index 100%
rename from packages/playground/css/mod.module.scss
rename to playground/css/mod.module.scss
diff --git a/packages/playground/css/nested/_index.scss b/playground/css/nested/_index.scss
similarity index 100%
rename from packages/playground/css/nested/_index.scss
rename to playground/css/nested/_index.scss
diff --git a/packages/playground/css/nested/_partial.scss b/playground/css/nested/_partial.scss
similarity index 100%
rename from packages/playground/css/nested/_partial.scss
rename to playground/css/nested/_partial.scss
diff --git a/packages/playground/css/nested/css-in-less-2.less b/playground/css/nested/css-in-less-2.less
similarity index 100%
rename from packages/playground/css/nested/css-in-less-2.less
rename to playground/css/nested/css-in-less-2.less
diff --git a/packages/playground/css/nested/css-in-less.css b/playground/css/nested/css-in-less.css
similarity index 100%
rename from packages/playground/css/nested/css-in-less.css
rename to playground/css/nested/css-in-less.css
diff --git a/packages/playground/css/nested/css-in-less.less b/playground/css/nested/css-in-less.less
similarity index 100%
rename from packages/playground/css/nested/css-in-less.less
rename to playground/css/nested/css-in-less.less
diff --git a/packages/playground/css/nested/css-in-scss.css b/playground/css/nested/css-in-scss.css
similarity index 100%
rename from packages/playground/css/nested/css-in-scss.css
rename to playground/css/nested/css-in-scss.css
diff --git a/packages/playground/css/nested/icon.png b/playground/css/nested/icon.png
similarity index 100%
rename from packages/playground/css/nested/icon.png
rename to playground/css/nested/icon.png
diff --git a/packages/playground/css/nested/nested.less b/playground/css/nested/nested.less
similarity index 100%
rename from packages/playground/css/nested/nested.less
rename to playground/css/nested/nested.less
diff --git a/packages/playground/css/nested/nested.styl b/playground/css/nested/nested.styl
similarity index 100%
rename from packages/playground/css/nested/nested.styl
rename to playground/css/nested/nested.styl
diff --git a/packages/playground/css/ok.png b/playground/css/ok.png
similarity index 100%
rename from packages/playground/css/ok.png
rename to playground/css/ok.png
diff --git a/packages/playground/css/options/absolute-import.styl b/playground/css/options/absolute-import.styl
similarity index 100%
rename from packages/playground/css/options/absolute-import.styl
rename to playground/css/options/absolute-import.styl
diff --git a/packages/playground/css/options/relative-import.styl b/playground/css/options/relative-import.styl
similarity index 100%
rename from packages/playground/css/options/relative-import.styl
rename to playground/css/options/relative-import.styl
diff --git a/packages/playground/css/package.json b/playground/css/package.json
similarity index 79%
rename from packages/playground/css/package.json
rename to playground/css/package.json
index b45063100be089..daaad66a9bb41f 100644
--- a/packages/playground/css/package.json
+++ b/playground/css/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"devDependencies": {
@@ -13,7 +13,7 @@
"fast-glob": "^3.2.11",
"less": "^4.1.2",
"postcss-nested": "^5.0.6",
- "sass": "^1.43.4",
+ "sass": "^1.51.0",
"stylus": "^0.55.0"
}
}
diff --git a/packages/playground/css/pkg-dep/_index.scss b/playground/css/pkg-dep/_index.scss
similarity index 100%
rename from packages/playground/css/pkg-dep/_index.scss
rename to playground/css/pkg-dep/_index.scss
diff --git a/packages/playground/css/pkg-dep/index.js b/playground/css/pkg-dep/index.js
similarity index 100%
rename from packages/playground/css/pkg-dep/index.js
rename to playground/css/pkg-dep/index.js
diff --git a/packages/playground/css/pkg-dep/package.json b/playground/css/pkg-dep/package.json
similarity index 100%
rename from packages/playground/css/pkg-dep/package.json
rename to playground/css/pkg-dep/package.json
diff --git a/packages/playground/css/postcss-caching/blue-app/imported.css b/playground/css/postcss-caching/blue-app/imported.css
similarity index 100%
rename from packages/playground/css/postcss-caching/blue-app/imported.css
rename to playground/css/postcss-caching/blue-app/imported.css
diff --git a/packages/playground/css/postcss-caching/blue-app/index.html b/playground/css/postcss-caching/blue-app/index.html
similarity index 100%
rename from packages/playground/css/postcss-caching/blue-app/index.html
rename to playground/css/postcss-caching/blue-app/index.html
diff --git a/packages/playground/css/postcss-caching/blue-app/main.js b/playground/css/postcss-caching/blue-app/main.js
similarity index 100%
rename from packages/playground/css/postcss-caching/blue-app/main.js
rename to playground/css/postcss-caching/blue-app/main.js
diff --git a/packages/playground/css/postcss-caching/blue-app/package.json b/playground/css/postcss-caching/blue-app/package.json
similarity index 71%
rename from packages/playground/css/postcss-caching/blue-app/package.json
rename to playground/css/postcss-caching/blue-app/package.json
index 34be8916bb2c9e..82ba64fadd44b4 100644
--- a/packages/playground/css/postcss-caching/blue-app/package.json
+++ b/playground/css/postcss-caching/blue-app/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/css/postcss-caching/blue-app/postcss.config.js b/playground/css/postcss-caching/blue-app/postcss.config.js
similarity index 100%
rename from packages/playground/css/postcss-caching/blue-app/postcss.config.js
rename to playground/css/postcss-caching/blue-app/postcss.config.js
diff --git a/packages/playground/css/postcss-caching/css.spec.ts b/playground/css/postcss-caching/css.spec.ts
similarity index 93%
rename from packages/playground/css/postcss-caching/css.spec.ts
rename to playground/css/postcss-caching/css.spec.ts
index 6c85d127003680..e8ba73154b6bc8 100644
--- a/packages/playground/css/postcss-caching/css.spec.ts
+++ b/playground/css/postcss-caching/css.spec.ts
@@ -1,9 +1,9 @@
-import { getColor } from '../../testUtils'
+import { getColor, ports } from '../../testUtils'
import { createServer } from 'vite'
import path from 'path'
test('postcss config', async () => {
- const port = 5005
+ const port = ports['css/postcss-caching']
const startServer = async (root) => {
const server = await createServer({
root,
diff --git a/packages/playground/css/postcss-caching/green-app/imported.css b/playground/css/postcss-caching/green-app/imported.css
similarity index 100%
rename from packages/playground/css/postcss-caching/green-app/imported.css
rename to playground/css/postcss-caching/green-app/imported.css
diff --git a/packages/playground/css/postcss-caching/green-app/index.html b/playground/css/postcss-caching/green-app/index.html
similarity index 100%
rename from packages/playground/css/postcss-caching/green-app/index.html
rename to playground/css/postcss-caching/green-app/index.html
diff --git a/packages/playground/css/postcss-caching/green-app/main.js b/playground/css/postcss-caching/green-app/main.js
similarity index 100%
rename from packages/playground/css/postcss-caching/green-app/main.js
rename to playground/css/postcss-caching/green-app/main.js
diff --git a/packages/playground/css/postcss-caching/green-app/package.json b/playground/css/postcss-caching/green-app/package.json
similarity index 71%
rename from packages/playground/css/postcss-caching/green-app/package.json
rename to playground/css/postcss-caching/green-app/package.json
index 947b30384a1a53..72bd0f45b8865f 100644
--- a/packages/playground/css/postcss-caching/green-app/package.json
+++ b/playground/css/postcss-caching/green-app/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/css/postcss-caching/green-app/postcss.config.js b/playground/css/postcss-caching/green-app/postcss.config.js
similarity index 100%
rename from packages/playground/css/postcss-caching/green-app/postcss.config.js
rename to playground/css/postcss-caching/green-app/postcss.config.js
diff --git a/playground/css/postcss-source-input.css b/playground/css/postcss-source-input.css
new file mode 100644
index 00000000000000..c6c3cb0c16dece
--- /dev/null
+++ b/playground/css/postcss-source-input.css
@@ -0,0 +1 @@
+@source-input;
diff --git a/packages/playground/css/postcss.config.js b/playground/css/postcss.config.js
similarity index 68%
rename from packages/playground/css/postcss.config.js
rename to playground/css/postcss.config.js
index f3d6ac9548b6a9..33058023541515 100644
--- a/packages/playground/css/postcss.config.js
+++ b/playground/css/postcss.config.js
@@ -1,5 +1,5 @@
module.exports = {
- plugins: [require('postcss-nested'), testDirDep]
+ plugins: [require('postcss-nested'), testDirDep, testSourceInput]
}
const fs = require('fs')
@@ -35,3 +35,20 @@ function testDirDep() {
}
}
testDirDep.postcss = true
+
+function testSourceInput() {
+ return {
+ postcssPlugin: 'source-input',
+ AtRule(atRule) {
+ if (atRule.name === 'source-input') {
+ atRule.after(
+ `.source-input::before { content: ${JSON.stringify(
+ atRule.source.input.from
+ )}; }`
+ )
+ atRule.remove()
+ }
+ }
+ }
+}
+testSourceInput.postcss = true
diff --git a/packages/playground/css/raw-imported.css b/playground/css/raw-imported.css
similarity index 100%
rename from packages/playground/css/raw-imported.css
rename to playground/css/raw-imported.css
diff --git a/packages/playground/css/sass.scss b/playground/css/sass.scss
similarity index 100%
rename from packages/playground/css/sass.scss
rename to playground/css/sass.scss
diff --git a/packages/playground/css/stylus.styl b/playground/css/stylus.styl
similarity index 100%
rename from packages/playground/css/stylus.styl
rename to playground/css/stylus.styl
diff --git a/packages/playground/css/vite.config.js b/playground/css/vite.config.js
similarity index 100%
rename from packages/playground/css/vite.config.js
rename to playground/css/vite.config.js
diff --git a/packages/playground/data-uri/__tests__/data-uri.spec.ts b/playground/data-uri/__tests__/data-uri.spec.ts
similarity index 100%
rename from packages/playground/data-uri/__tests__/data-uri.spec.ts
rename to playground/data-uri/__tests__/data-uri.spec.ts
diff --git a/packages/playground/data-uri/index.html b/playground/data-uri/index.html
similarity index 100%
rename from packages/playground/data-uri/index.html
rename to playground/data-uri/index.html
diff --git a/packages/playground/data-uri/package.json b/playground/data-uri/package.json
similarity index 72%
rename from packages/playground/data-uri/package.json
rename to playground/data-uri/package.json
index a07c9a2cd6a663..4d30ad97b9acbb 100644
--- a/packages/playground/data-uri/package.json
+++ b/playground/data-uri/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/define/__tests__/define.spec.ts b/playground/define/__tests__/define.spec.ts
similarity index 76%
rename from packages/playground/define/__tests__/define.spec.ts
rename to playground/define/__tests__/define.spec.ts
index 709f7a935dc8c1..5d9707e70b47ba 100644
--- a/packages/playground/define/__tests__/define.spec.ts
+++ b/playground/define/__tests__/define.spec.ts
@@ -20,6 +20,14 @@ test('string', async () => {
expect(await page.textContent('.spread-array')).toBe(
JSON.stringify([...defines.__STRING__])
)
+ expect(await page.textContent('.dollar-identifier')).toBe(
+ String(defines.$DOLLAR)
+ )
+ expect(await page.textContent('.unicode-identifier')).toBe(
+ String(defines.ÖUNICODE_LETTERɵ)
+ )
+ expect(await page.textContent('.no-identifier-substring')).toBe(String(true))
+ expect(await page.textContent('.no-property')).toBe(String(true))
// html would't need to define replacement
expect(await page.textContent('.exp-define')).toBe('__EXP__')
expect(await page.textContent('.import-json')).toBe('__EXP__')
diff --git a/packages/playground/define/data.json b/playground/define/data.json
similarity index 100%
rename from packages/playground/define/data.json
rename to playground/define/data.json
diff --git a/packages/playground/define/index.html b/playground/define/index.html
similarity index 71%
rename from packages/playground/define/index.html
rename to playground/define/index.html
index da78d192216b11..c89a3fe02218ff 100644
--- a/packages/playground/define/index.html
+++ b/playground/define/index.html
@@ -9,6 +9,10 @@
Define
process as property:
spread object:
spread array:
+
dollar identifier:
+
unicode identifier:
+
no property:
+
no identifier substring:
define variable in html: __EXP__
import json:
@@ -28,6 +32,15 @@
Define
})
)
text('.spread-array', JSON.stringify([...`"${__STRING__}"`]))
+ text('.dollar-identifier', $DOLLAR)
+ text('.unicode-identifier', ÖUNICODE_LETTERɵ)
+
+ // make sure these kinds of use are NOT replaced:
+ const obj = { [`${'_'}_EXP__`]: true }
+ text('.no-property', obj.__EXP__)
+
+ window[`${'_'}_EXP__SUBSTR__`] = true
+ text('.no-identifier-substring', __EXP__SUBSTR__)
import dataJson from './data.json'
text('.import-json', dataJson.foo)
diff --git a/packages/playground/define/package.json b/playground/define/package.json
similarity index 72%
rename from packages/playground/define/package.json
rename to playground/define/package.json
index c8f926f5c910ff..7c46b3020125fe 100644
--- a/packages/playground/define/package.json
+++ b/playground/define/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/define/vite.config.js b/playground/define/vite.config.js
similarity index 72%
rename from packages/playground/define/vite.config.js
rename to playground/define/vite.config.js
index 848abd09322df6..88173fe654b58d 100644
--- a/packages/playground/define/vite.config.js
+++ b/playground/define/vite.config.js
@@ -15,7 +15,9 @@ module.exports = {
}
}
},
- __VAR_NAME__: false,
- 'process.env.SOMEVAR': '"SOMEVAR"'
+ 'process.env.SOMEVAR': '"SOMEVAR"',
+ $DOLLAR: 456,
+ ÖUNICODE_LETTERɵ: 789,
+ __VAR_NAME__: false
}
}
diff --git a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts b/playground/dynamic-import/__tests__/dynamic-import.spec.ts
similarity index 89%
rename from packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts
rename to playground/dynamic-import/__tests__/dynamic-import.spec.ts
index c7157ef4652ec6..4730b5e990a1c3 100644
--- a/packages/playground/dynamic-import/__tests__/dynamic-import.spec.ts
+++ b/playground/dynamic-import/__tests__/dynamic-import.spec.ts
@@ -1,4 +1,4 @@
-import { isBuild, untilUpdated } from '../../testUtils'
+import { getColor, isBuild, untilUpdated } from '../../testUtils'
test('should load literal dynamic import', async () => {
await page.click('.baz')
@@ -59,3 +59,8 @@ test('should load dynamic import with css', async () => {
true
)
})
+
+test('should load dynamic import with css in package', async () => {
+ await page.click('.pkg-css')
+ await untilUpdated(() => getColor('.pkg-css'), 'blue', true)
+})
diff --git a/packages/playground/dynamic-import/css/index.css b/playground/dynamic-import/css/index.css
similarity index 100%
rename from packages/playground/dynamic-import/css/index.css
rename to playground/dynamic-import/css/index.css
diff --git a/packages/playground/dynamic-import/index.html b/playground/dynamic-import/index.html
similarity index 91%
rename from packages/playground/dynamic-import/index.html
rename to playground/dynamic-import/index.html
index c87ef2a17f48d5..8e18204a7e4296 100644
--- a/packages/playground/dynamic-import/index.html
+++ b/playground/dynamic-import/index.html
@@ -8,6 +8,7 @@
+
diff --git a/packages/playground/dynamic-import/mxd.js b/playground/dynamic-import/mxd.js
similarity index 100%
rename from packages/playground/dynamic-import/mxd.js
rename to playground/dynamic-import/mxd.js
diff --git a/packages/playground/dynamic-import/mxd.json b/playground/dynamic-import/mxd.json
similarity index 100%
rename from packages/playground/dynamic-import/mxd.json
rename to playground/dynamic-import/mxd.json
diff --git a/playground/dynamic-import/nested/deps.js b/playground/dynamic-import/nested/deps.js
new file mode 100644
index 00000000000000..88fd4787941fd0
--- /dev/null
+++ b/playground/dynamic-import/nested/deps.js
@@ -0,0 +1,3 @@
+/* don't include dynamic import inside this file */
+
+import 'pkg'
diff --git a/packages/playground/dynamic-import/nested/index.js b/playground/dynamic-import/nested/index.js
similarity index 93%
rename from packages/playground/dynamic-import/nested/index.js
rename to playground/dynamic-import/nested/index.js
index 5518c56a35a2cc..f84ec00380d604 100644
--- a/packages/playground/dynamic-import/nested/index.js
+++ b/playground/dynamic-import/nested/index.js
@@ -70,6 +70,11 @@ document.querySelector('.css').addEventListener('click', async () => {
text('.view', 'dynamic import css')
})
+document.querySelector('.pkg-css').addEventListener('click', async () => {
+ await import('./deps')
+ text('.view', 'dynamic import css in package')
+})
+
function text(el, text) {
document.querySelector(el).textContent = text
}
diff --git a/packages/playground/dynamic-import/nested/shared.js b/playground/dynamic-import/nested/shared.js
similarity index 100%
rename from packages/playground/dynamic-import/nested/shared.js
rename to playground/dynamic-import/nested/shared.js
diff --git a/playground/dynamic-import/package.json b/playground/dynamic-import/package.json
new file mode 100644
index 00000000000000..9492fc0173e2c2
--- /dev/null
+++ b/playground/dynamic-import/package.json
@@ -0,0 +1,15 @@
+{
+ "name": "test-dynamic-import",
+ "private": true,
+ "version": "0.0.0",
+ "scripts": {
+ "dev": "vite",
+ "build": "vite build",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
+ "preview": "vite preview",
+ "postinstall": "ts-node ../../scripts/patchFileDeps.ts"
+ },
+ "dependencies": {
+ "pkg": "file:./pkg"
+ }
+}
diff --git a/playground/dynamic-import/pkg/index.js b/playground/dynamic-import/pkg/index.js
new file mode 100644
index 00000000000000..20f705c0b4a8c9
--- /dev/null
+++ b/playground/dynamic-import/pkg/index.js
@@ -0,0 +1 @@
+import('./pkg.css')
diff --git a/playground/dynamic-import/pkg/package.json b/playground/dynamic-import/pkg/package.json
new file mode 100644
index 00000000000000..1eab564572e245
--- /dev/null
+++ b/playground/dynamic-import/pkg/package.json
@@ -0,0 +1,7 @@
+{
+ "name": "pkg",
+ "type": "module",
+ "private": true,
+ "version": "1.0.0",
+ "main": "index.js"
+}
diff --git a/playground/dynamic-import/pkg/pkg.css b/playground/dynamic-import/pkg/pkg.css
new file mode 100644
index 00000000000000..349d669b6829bf
--- /dev/null
+++ b/playground/dynamic-import/pkg/pkg.css
@@ -0,0 +1,3 @@
+.pkg-css {
+ color: blue;
+}
diff --git a/packages/playground/dynamic-import/qux.js b/playground/dynamic-import/qux.js
similarity index 100%
rename from packages/playground/dynamic-import/qux.js
rename to playground/dynamic-import/qux.js
diff --git a/packages/playground/dynamic-import/views/bar.js b/playground/dynamic-import/views/bar.js
similarity index 100%
rename from packages/playground/dynamic-import/views/bar.js
rename to playground/dynamic-import/views/bar.js
diff --git a/packages/playground/dynamic-import/views/baz.js b/playground/dynamic-import/views/baz.js
similarity index 100%
rename from packages/playground/dynamic-import/views/baz.js
rename to playground/dynamic-import/views/baz.js
diff --git a/packages/playground/dynamic-import/views/foo.js b/playground/dynamic-import/views/foo.js
similarity index 100%
rename from packages/playground/dynamic-import/views/foo.js
rename to playground/dynamic-import/views/foo.js
diff --git a/packages/playground/dynamic-import/vite.config.js b/playground/dynamic-import/vite.config.js
similarity index 100%
rename from packages/playground/dynamic-import/vite.config.js
rename to playground/dynamic-import/vite.config.js
diff --git a/packages/playground/env-nested/.env b/playground/env-nested/.env
similarity index 100%
rename from packages/playground/env-nested/.env
rename to playground/env-nested/.env
diff --git a/packages/playground/env-nested/__tests__/env-nested.spec.ts b/playground/env-nested/__tests__/env-nested.spec.ts
similarity index 100%
rename from packages/playground/env-nested/__tests__/env-nested.spec.ts
rename to playground/env-nested/__tests__/env-nested.spec.ts
diff --git a/packages/playground/env-nested/envs/.env.development b/playground/env-nested/envs/.env.development
similarity index 100%
rename from packages/playground/env-nested/envs/.env.development
rename to playground/env-nested/envs/.env.development
diff --git a/packages/playground/env-nested/envs/.env.production b/playground/env-nested/envs/.env.production
similarity index 100%
rename from packages/playground/env-nested/envs/.env.production
rename to playground/env-nested/envs/.env.production
diff --git a/packages/playground/env-nested/index.html b/playground/env-nested/index.html
similarity index 100%
rename from packages/playground/env-nested/index.html
rename to playground/env-nested/index.html
diff --git a/packages/playground/env-nested/package.json b/playground/env-nested/package.json
similarity index 72%
rename from packages/playground/env-nested/package.json
rename to playground/env-nested/package.json
index 8fecc69a41c2f4..530b4e621005b0 100644
--- a/packages/playground/env-nested/package.json
+++ b/playground/env-nested/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/env-nested/vite.config.js b/playground/env-nested/vite.config.js
similarity index 100%
rename from packages/playground/env-nested/vite.config.js
rename to playground/env-nested/vite.config.js
diff --git a/packages/playground/env/.env b/playground/env/.env
similarity index 100%
rename from packages/playground/env/.env
rename to playground/env/.env
diff --git a/packages/playground/env/.env.development b/playground/env/.env.development
similarity index 100%
rename from packages/playground/env/.env.development
rename to playground/env/.env.development
diff --git a/packages/playground/env/.env.production b/playground/env/.env.production
similarity index 100%
rename from packages/playground/env/.env.production
rename to playground/env/.env.production
diff --git a/packages/playground/env/__tests__/env.spec.ts b/playground/env/__tests__/env.spec.ts
similarity index 100%
rename from packages/playground/env/__tests__/env.spec.ts
rename to playground/env/__tests__/env.spec.ts
diff --git a/packages/playground/env/index.html b/playground/env/index.html
similarity index 100%
rename from packages/playground/env/index.html
rename to playground/env/index.html
diff --git a/packages/playground/env/package.json b/playground/env/package.json
similarity index 81%
rename from packages/playground/env/package.json
rename to playground/env/package.json
index a97b5150530267..271cbf0a7d20c0 100644
--- a/packages/playground/env/package.json
+++ b/playground/env/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "cross-env VITE_INLINE=inline-serve vite",
"build": "cross-env VITE_INLINE=inline-build vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"devDependencies": {
diff --git a/packages/playground/env/vite.config.js b/playground/env/vite.config.js
similarity index 100%
rename from packages/playground/env/vite.config.js
rename to playground/env/vite.config.js
diff --git a/packages/playground/extensions/__tests__/extensions.spec.ts b/playground/extensions/__tests__/extensions.spec.ts
similarity index 100%
rename from packages/playground/extensions/__tests__/extensions.spec.ts
rename to playground/extensions/__tests__/extensions.spec.ts
diff --git a/packages/playground/extensions/index.html b/playground/extensions/index.html
similarity index 100%
rename from packages/playground/extensions/index.html
rename to playground/extensions/index.html
diff --git a/packages/playground/extensions/package.json b/playground/extensions/package.json
similarity index 69%
rename from packages/playground/extensions/package.json
rename to playground/extensions/package.json
index d09b7da4d5300b..c653486edf6be6 100644
--- a/packages/playground/extensions/package.json
+++ b/playground/extensions/package.json
@@ -5,10 +5,10 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"dependencies": {
- "vue": "^3.2.25"
+ "vue": "^3.2.33"
}
}
diff --git a/packages/playground/extensions/vite.config.js b/playground/extensions/vite.config.js
similarity index 100%
rename from packages/playground/extensions/vite.config.js
rename to playground/extensions/vite.config.js
diff --git a/packages/playground/file-delete-restore/App.jsx b/playground/file-delete-restore/App.jsx
similarity index 100%
rename from packages/playground/file-delete-restore/App.jsx
rename to playground/file-delete-restore/App.jsx
diff --git a/packages/playground/file-delete-restore/Child.jsx b/playground/file-delete-restore/Child.jsx
similarity index 100%
rename from packages/playground/file-delete-restore/Child.jsx
rename to playground/file-delete-restore/Child.jsx
diff --git a/packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts b/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts
similarity index 100%
rename from packages/playground/file-delete-restore/__tests__/file-delete-restore.spec.ts
rename to playground/file-delete-restore/__tests__/file-delete-restore.spec.ts
diff --git a/packages/playground/file-delete-restore/index.html b/playground/file-delete-restore/index.html
similarity index 100%
rename from packages/playground/file-delete-restore/index.html
rename to playground/file-delete-restore/index.html
diff --git a/packages/playground/file-delete-restore/package.json b/playground/file-delete-restore/package.json
similarity index 83%
rename from packages/playground/file-delete-restore/package.json
rename to playground/file-delete-restore/package.json
index 8f9caa3578f8bd..b9c511aacfa62e 100644
--- a/packages/playground/file-delete-restore/package.json
+++ b/playground/file-delete-restore/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"dependencies": {
diff --git a/packages/playground/file-delete-restore/vite.config.js b/playground/file-delete-restore/vite.config.js
similarity index 100%
rename from packages/playground/file-delete-restore/vite.config.js
rename to playground/file-delete-restore/vite.config.js
diff --git a/packages/playground/fs-serve/__tests__/fs-serve.spec.ts b/playground/fs-serve/__tests__/fs-serve.spec.ts
similarity index 100%
rename from packages/playground/fs-serve/__tests__/fs-serve.spec.ts
rename to playground/fs-serve/__tests__/fs-serve.spec.ts
diff --git a/packages/playground/fs-serve/entry.js b/playground/fs-serve/entry.js
similarity index 100%
rename from packages/playground/fs-serve/entry.js
rename to playground/fs-serve/entry.js
diff --git a/packages/playground/fs-serve/nested/foo.js b/playground/fs-serve/nested/foo.js
similarity index 100%
rename from packages/playground/fs-serve/nested/foo.js
rename to playground/fs-serve/nested/foo.js
diff --git a/packages/playground/fs-serve/package.json b/playground/fs-serve/package.json
similarity index 73%
rename from packages/playground/fs-serve/package.json
rename to playground/fs-serve/package.json
index 45497d2a3c5e8a..c50be06a8cb286 100644
--- a/packages/playground/fs-serve/package.json
+++ b/playground/fs-serve/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite root",
"build": "vite build root",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/fs-serve/root/src/.env b/playground/fs-serve/root/src/.env
similarity index 100%
rename from packages/playground/fs-serve/root/src/.env
rename to playground/fs-serve/root/src/.env
diff --git a/packages/playground/fs-serve/root/src/index.html b/playground/fs-serve/root/src/index.html
similarity index 100%
rename from packages/playground/fs-serve/root/src/index.html
rename to playground/fs-serve/root/src/index.html
diff --git a/packages/playground/fs-serve/root/src/safe.txt b/playground/fs-serve/root/src/safe.txt
similarity index 100%
rename from packages/playground/fs-serve/root/src/safe.txt
rename to playground/fs-serve/root/src/safe.txt
diff --git "a/packages/playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.json" "b/playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.json"
similarity index 100%
rename from "packages/playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.json"
rename to "playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.json"
diff --git "a/packages/playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.txt" "b/playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.txt"
similarity index 100%
rename from "packages/playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.txt"
rename to "playground/fs-serve/root/src/special characters \303\245\303\244\303\266/safe.txt"
diff --git a/packages/playground/fs-serve/root/src/subdir/safe.txt b/playground/fs-serve/root/src/subdir/safe.txt
similarity index 100%
rename from packages/playground/fs-serve/root/src/subdir/safe.txt
rename to playground/fs-serve/root/src/subdir/safe.txt
diff --git a/packages/playground/fs-serve/root/unsafe.txt b/playground/fs-serve/root/unsafe.txt
similarity index 100%
rename from packages/playground/fs-serve/root/unsafe.txt
rename to playground/fs-serve/root/unsafe.txt
diff --git a/packages/playground/fs-serve/root/vite.config.js b/playground/fs-serve/root/vite.config.js
similarity index 100%
rename from packages/playground/fs-serve/root/vite.config.js
rename to playground/fs-serve/root/vite.config.js
diff --git a/packages/playground/fs-serve/safe.json b/playground/fs-serve/safe.json
similarity index 100%
rename from packages/playground/fs-serve/safe.json
rename to playground/fs-serve/safe.json
diff --git a/packages/playground/fs-serve/unsafe.json b/playground/fs-serve/unsafe.json
similarity index 100%
rename from packages/playground/fs-serve/unsafe.json
rename to playground/fs-serve/unsafe.json
diff --git a/packages/playground/glob-import/__tests__/glob-import.spec.ts b/playground/glob-import/__tests__/glob-import.spec.ts
similarity index 98%
rename from packages/playground/glob-import/__tests__/glob-import.spec.ts
rename to playground/glob-import/__tests__/glob-import.spec.ts
index ebdf6c0ab29193..d738ccec1d4c97 100644
--- a/packages/playground/glob-import/__tests__/glob-import.spec.ts
+++ b/playground/glob-import/__tests__/glob-import.spec.ts
@@ -42,7 +42,7 @@ const allResult = {
},
'/dir/index.js': {
globWithAlias: {
- './alias.js': {
+ '/dir/alias.js': {
default: 'hi'
}
},
@@ -67,7 +67,7 @@ const rawResult = {
}
const relativeRawResult = {
- '../glob-import/dir/baz.json': {
+ './dir/baz.json': {
msg: 'baz'
}
}
diff --git a/packages/playground/glob-import/dir/alias.js b/playground/glob-import/dir/alias.js
similarity index 100%
rename from packages/playground/glob-import/dir/alias.js
rename to playground/glob-import/dir/alias.js
diff --git a/packages/playground/glob-import/dir/baz.json b/playground/glob-import/dir/baz.json
similarity index 100%
rename from packages/playground/glob-import/dir/baz.json
rename to playground/glob-import/dir/baz.json
diff --git a/packages/playground/glob-import/dir/foo.js b/playground/glob-import/dir/foo.js
similarity index 100%
rename from packages/playground/glob-import/dir/foo.js
rename to playground/glob-import/dir/foo.js
diff --git a/playground/glob-import/dir/index.js b/playground/glob-import/dir/index.js
new file mode 100644
index 00000000000000..ab298abed485b3
--- /dev/null
+++ b/playground/glob-import/dir/index.js
@@ -0,0 +1,4 @@
+const modules = import.meta.glob('./*.(js|ts)', { eager: true })
+const globWithAlias = import.meta.glob('@dir/al*.js', { eager: true })
+
+export { modules, globWithAlias }
diff --git a/playground/glob-import/dir/nested/bar.js b/playground/glob-import/dir/nested/bar.js
new file mode 100644
index 00000000000000..bb23a5a141de8e
--- /dev/null
+++ b/playground/glob-import/dir/nested/bar.js
@@ -0,0 +1,4 @@
+const modules = import.meta.glob('../*.json', { eager: true })
+
+export const msg = 'bar'
+export { modules }
diff --git a/packages/playground/glob-import/dir/node_modules/hoge.js b/playground/glob-import/dir/node_modules/hoge.js
similarity index 100%
rename from packages/playground/glob-import/dir/node_modules/hoge.js
rename to playground/glob-import/dir/node_modules/hoge.js
diff --git a/packages/playground/glob-import/index.html b/playground/glob-import/index.html
similarity index 88%
rename from packages/playground/glob-import/index.html
rename to playground/glob-import/index.html
index 64f456aeb4d6a2..8466a6d0495881 100644
--- a/packages/playground/glob-import/index.html
+++ b/playground/glob-import/index.html
@@ -40,8 +40,9 @@
diff --git a/playground/hmr/counter/index.ts b/playground/hmr/counter/index.ts
new file mode 100644
index 00000000000000..0230140278989f
--- /dev/null
+++ b/playground/hmr/counter/index.ts
@@ -0,0 +1,12 @@
+const btn = document.querySelector('button')
+let count = 0
+const update = () => {
+ btn.textContent = `Counter ${count}`
+}
+btn.onclick = () => {
+ count++
+ update()
+}
+function neverCalled() {
+ import('./dep')
+}
diff --git a/packages/playground/hmr/customFile.js b/playground/hmr/customFile.js
similarity index 100%
rename from packages/playground/hmr/customFile.js
rename to playground/hmr/customFile.js
diff --git a/packages/playground/hmr/event.d.ts b/playground/hmr/event.d.ts
similarity index 100%
rename from packages/playground/hmr/event.d.ts
rename to playground/hmr/event.d.ts
diff --git a/packages/playground/hmr/global.css b/playground/hmr/global.css
similarity index 100%
rename from packages/playground/hmr/global.css
rename to playground/hmr/global.css
diff --git a/packages/playground/hmr/hmr.ts b/playground/hmr/hmr.ts
similarity index 100%
rename from packages/playground/hmr/hmr.ts
rename to playground/hmr/hmr.ts
diff --git a/packages/playground/hmr/hmrDep.js b/playground/hmr/hmrDep.js
similarity index 100%
rename from packages/playground/hmr/hmrDep.js
rename to playground/hmr/hmrDep.js
diff --git a/packages/playground/hmr/hmrNestedDep.js b/playground/hmr/hmrNestedDep.js
similarity index 100%
rename from packages/playground/hmr/hmrNestedDep.js
rename to playground/hmr/hmrNestedDep.js
diff --git a/packages/playground/vue/public/icon.png b/playground/hmr/icon.png
similarity index 100%
rename from packages/playground/vue/public/icon.png
rename to playground/hmr/icon.png
diff --git a/packages/playground/hmr/index.html b/playground/hmr/index.html
similarity index 64%
rename from packages/playground/hmr/index.html
rename to playground/hmr/index.html
index 0add7c26011a01..65a2ed381b027a 100644
--- a/packages/playground/hmr/index.html
+++ b/playground/hmr/index.html
@@ -1,5 +1,13 @@
+
@@ -8,3 +16,4 @@
+
diff --git a/packages/playground/hmr/package.json b/playground/hmr/package.json
similarity index 71%
rename from packages/playground/hmr/package.json
rename to playground/hmr/package.json
index fa3654bdbdca85..b797d181b17ece 100644
--- a/packages/playground/hmr/package.json
+++ b/playground/hmr/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/hmr/tsconfig.json b/playground/hmr/tsconfig.json
similarity index 100%
rename from packages/playground/hmr/tsconfig.json
rename to playground/hmr/tsconfig.json
diff --git "a/packages/playground/hmr/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html" "b/playground/hmr/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html"
similarity index 100%
rename from "packages/playground/hmr/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html"
rename to "playground/hmr/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html"
diff --git a/packages/playground/hmr/vite.config.ts b/playground/hmr/vite.config.ts
similarity index 100%
rename from packages/playground/hmr/vite.config.ts
rename to playground/hmr/vite.config.ts
diff --git a/packages/playground/html/__tests__/html.spec.ts b/playground/html/__tests__/html.spec.ts
similarity index 99%
rename from packages/playground/html/__tests__/html.spec.ts
rename to playground/html/__tests__/html.spec.ts
index 66f537e5026361..834db1f6126cad 100644
--- a/packages/playground/html/__tests__/html.spec.ts
+++ b/playground/html/__tests__/html.spec.ts
@@ -231,7 +231,7 @@ if (!isBuild) {
await editFile('invalid.html', (content) => {
return content.replace('
Good')
})
- const content = await page.waitForSelector('text=Good Html')
+ const content = await page.waitForSelector('text=Good HTML')
expect(content).toBeTruthy()
})
})
diff --git a/packages/playground/html/common.css b/playground/html/common.css
similarity index 100%
rename from packages/playground/html/common.css
rename to playground/html/common.css
diff --git a/packages/playground/html/emptyAttr.html b/playground/html/emptyAttr.html
similarity index 100%
rename from packages/playground/html/emptyAttr.html
rename to playground/html/emptyAttr.html
diff --git a/packages/playground/html/foo.html b/playground/html/foo.html
similarity index 100%
rename from packages/playground/html/foo.html
rename to playground/html/foo.html
diff --git a/packages/playground/html/index.html b/playground/html/index.html
similarity index 50%
rename from packages/playground/html/index.html
rename to playground/html/index.html
index 7320ff2b097db0..783cad93172f7a 100644
--- a/packages/playground/html/index.html
+++ b/playground/html/index.html
@@ -5,3 +5,6 @@
Hello
+
+
+
diff --git a/packages/playground/html/inline/common.js b/playground/html/inline/common.js
similarity index 100%
rename from packages/playground/html/inline/common.js
rename to playground/html/inline/common.js
diff --git a/packages/playground/html/inline/dep1.js b/playground/html/inline/dep1.js
similarity index 100%
rename from packages/playground/html/inline/dep1.js
rename to playground/html/inline/dep1.js
diff --git a/packages/playground/html/inline/dep2.js b/playground/html/inline/dep2.js
similarity index 100%
rename from packages/playground/html/inline/dep2.js
rename to playground/html/inline/dep2.js
diff --git a/packages/playground/html/inline/dep3.js b/playground/html/inline/dep3.js
similarity index 100%
rename from packages/playground/html/inline/dep3.js
rename to playground/html/inline/dep3.js
diff --git a/packages/playground/html/inline/module-graph.dot b/playground/html/inline/module-graph.dot
similarity index 100%
rename from packages/playground/html/inline/module-graph.dot
rename to playground/html/inline/module-graph.dot
diff --git a/packages/playground/html/inline/shared-1.html b/playground/html/inline/shared-1.html
similarity index 100%
rename from packages/playground/html/inline/shared-1.html
rename to playground/html/inline/shared-1.html
diff --git a/packages/playground/html/inline/shared-2.html b/playground/html/inline/shared-2.html
similarity index 100%
rename from packages/playground/html/inline/shared-2.html
rename to playground/html/inline/shared-2.html
diff --git a/packages/playground/html/inline/shared.js b/playground/html/inline/shared.js
similarity index 100%
rename from packages/playground/html/inline/shared.js
rename to playground/html/inline/shared.js
diff --git a/playground/html/inline/shared_a.html b/playground/html/inline/shared_a.html
new file mode 100644
index 00000000000000..31fbd8fcc34bdf
--- /dev/null
+++ b/playground/html/inline/shared_a.html
@@ -0,0 +1 @@
+
inline a
diff --git a/packages/playground/html/inline/unique.html b/playground/html/inline/unique.html
similarity index 100%
rename from packages/playground/html/inline/unique.html
rename to playground/html/inline/unique.html
diff --git a/packages/playground/html/inline/unique.js b/playground/html/inline/unique.js
similarity index 100%
rename from packages/playground/html/inline/unique.js
rename to playground/html/inline/unique.js
diff --git a/playground/html/invalid.html b/playground/html/invalid.html
new file mode 100644
index 00000000000000..8acea73f16bdad
--- /dev/null
+++ b/playground/html/invalid.html
@@ -0,0 +1 @@
+
diff --git a/packages/playground/html/link.html b/playground/html/link.html
similarity index 100%
rename from packages/playground/html/link.html
rename to playground/html/link.html
diff --git a/packages/playground/html/main.css b/playground/html/main.css
similarity index 100%
rename from packages/playground/html/main.css
rename to playground/html/main.css
diff --git a/packages/playground/html/main.js b/playground/html/main.js
similarity index 100%
rename from packages/playground/html/main.js
rename to playground/html/main.js
diff --git a/packages/playground/html/nested/index.html b/playground/html/nested/index.html
similarity index 100%
rename from packages/playground/html/nested/index.html
rename to playground/html/nested/index.html
diff --git a/packages/playground/html/nested/nested.css b/playground/html/nested/nested.css
similarity index 100%
rename from packages/playground/html/nested/nested.css
rename to playground/html/nested/nested.css
diff --git a/packages/playground/html/nested/nested.js b/playground/html/nested/nested.js
similarity index 100%
rename from packages/playground/html/nested/nested.js
rename to playground/html/nested/nested.js
diff --git a/packages/playground/html/noBody.html b/playground/html/noBody.html
similarity index 100%
rename from packages/playground/html/noBody.html
rename to playground/html/noBody.html
diff --git a/packages/playground/html/noHead.html b/playground/html/noHead.html
similarity index 100%
rename from packages/playground/html/noHead.html
rename to playground/html/noHead.html
diff --git a/packages/playground/html/package.json b/playground/html/package.json
similarity index 71%
rename from packages/playground/html/package.json
rename to playground/html/package.json
index a101033f8d3470..6db0bd91981ce0 100644
--- a/packages/playground/html/package.json
+++ b/playground/html/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/html/scriptAsync.html b/playground/html/scriptAsync.html
similarity index 100%
rename from packages/playground/html/scriptAsync.html
rename to playground/html/scriptAsync.html
diff --git a/packages/playground/html/scriptMixed.html b/playground/html/scriptMixed.html
similarity index 100%
rename from packages/playground/html/scriptMixed.html
rename to playground/html/scriptMixed.html
diff --git a/packages/playground/html/shared.js b/playground/html/shared.js
similarity index 100%
rename from packages/playground/html/shared.js
rename to playground/html/shared.js
diff --git "a/packages/playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html" "b/playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html"
similarity index 100%
rename from "packages/playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html"
rename to "playground/html/unicode-path/\344\270\255\346\226\207-\343\201\253\343\201\273\343\202\223\343\201\224-\355\225\234\352\270\200-\360\237\214\225\360\237\214\226\360\237\214\227/index.html"
diff --git a/packages/playground/html/vite.config.js b/playground/html/vite.config.js
similarity index 98%
rename from packages/playground/html/vite.config.js
rename to playground/html/vite.config.js
index 1703e02cc05366..bfe48675cbc18f 100644
--- a/packages/playground/html/vite.config.js
+++ b/playground/html/vite.config.js
@@ -17,6 +17,7 @@ module.exports = {
zeroJS: resolve(__dirname, 'zeroJS.html'),
noHead: resolve(__dirname, 'noHead.html'),
noBody: resolve(__dirname, 'noBody.html'),
+ inlinea: resolve(__dirname, 'inline/shared_a.html'),
inline1: resolve(__dirname, 'inline/shared-1.html'),
inline2: resolve(__dirname, 'inline/shared-2.html'),
inline3: resolve(__dirname, 'inline/unique.html'),
diff --git a/packages/playground/html/zeroJS.html b/playground/html/zeroJS.html
similarity index 100%
rename from packages/playground/html/zeroJS.html
rename to playground/html/zeroJS.html
diff --git a/packages/playground/js-sourcemap/__tests__/build.spec.ts b/playground/js-sourcemap/__tests__/build.spec.ts
similarity index 100%
rename from packages/playground/js-sourcemap/__tests__/build.spec.ts
rename to playground/js-sourcemap/__tests__/build.spec.ts
diff --git a/packages/playground/js-sourcemap/__tests__/serve.spec.ts b/playground/js-sourcemap/__tests__/serve.spec.ts
similarity index 100%
rename from packages/playground/js-sourcemap/__tests__/serve.spec.ts
rename to playground/js-sourcemap/__tests__/serve.spec.ts
diff --git a/packages/playground/js-sourcemap/bar.ts b/playground/js-sourcemap/bar.ts
similarity index 100%
rename from packages/playground/js-sourcemap/bar.ts
rename to playground/js-sourcemap/bar.ts
diff --git a/packages/playground/js-sourcemap/foo.js b/playground/js-sourcemap/foo.js
similarity index 100%
rename from packages/playground/js-sourcemap/foo.js
rename to playground/js-sourcemap/foo.js
diff --git a/packages/playground/js-sourcemap/index.html b/playground/js-sourcemap/index.html
similarity index 100%
rename from packages/playground/js-sourcemap/index.html
rename to playground/js-sourcemap/index.html
diff --git a/packages/playground/js-sourcemap/package.json b/playground/js-sourcemap/package.json
similarity index 72%
rename from packages/playground/js-sourcemap/package.json
rename to playground/js-sourcemap/package.json
index e5a97aea80830f..92b166d2f302c2 100644
--- a/packages/playground/js-sourcemap/package.json
+++ b/playground/js-sourcemap/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/packages/playground/js-sourcemap/vite.config.js b/playground/js-sourcemap/vite.config.js
similarity index 100%
rename from packages/playground/js-sourcemap/vite.config.js
rename to playground/js-sourcemap/vite.config.js
diff --git a/packages/playground/json/__tests__/json.spec.ts b/playground/json/__tests__/json.spec.ts
similarity index 100%
rename from packages/playground/json/__tests__/json.spec.ts
rename to playground/json/__tests__/json.spec.ts
diff --git a/packages/playground/json/index.html b/playground/json/index.html
similarity index 100%
rename from packages/playground/json/index.html
rename to playground/json/index.html
diff --git a/packages/playground/json/json-module/index.json b/playground/json/json-module/index.json
similarity index 100%
rename from packages/playground/json/json-module/index.json
rename to playground/json/json-module/index.json
diff --git a/packages/playground/json/json-module/package.json b/playground/json/json-module/package.json
similarity index 100%
rename from packages/playground/json/json-module/package.json
rename to playground/json/json-module/package.json
diff --git a/packages/playground/json/package.json b/playground/json/package.json
similarity index 60%
rename from packages/playground/json/package.json
rename to playground/json/package.json
index 203846bab73b48..a32140c1220d1a 100644
--- a/packages/playground/json/package.json
+++ b/playground/json/package.json
@@ -5,11 +5,11 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"devDependencies": {
- "vue": "^3.2.25",
- "json-module": "file:./json-module"
+ "json-module": "file:./json-module",
+ "vue": "^3.2.33"
}
}
diff --git a/packages/playground/json/public/public.json b/playground/json/public/public.json
similarity index 100%
rename from packages/playground/json/public/public.json
rename to playground/json/public/public.json
diff --git a/packages/playground/json/test.json b/playground/json/test.json
similarity index 100%
rename from packages/playground/json/test.json
rename to playground/json/test.json
diff --git a/packages/playground/legacy/__tests__/legacy.spec.ts b/playground/legacy/__tests__/legacy.spec.ts
similarity index 93%
rename from packages/playground/legacy/__tests__/legacy.spec.ts
rename to playground/legacy/__tests__/legacy.spec.ts
index 65bd39ff32b1d1..89cbadcacb2fd8 100644
--- a/packages/playground/legacy/__tests__/legacy.spec.ts
+++ b/playground/legacy/__tests__/legacy.spec.ts
@@ -59,9 +59,9 @@ test('correctly emits styles', async () => {
if (isBuild) {
test('should generate correct manifest', async () => {
const manifest = readManifest()
- expect(manifest['../../../vite/legacy-polyfills']).toBeDefined()
- expect(manifest['../../../vite/legacy-polyfills'].src).toBe(
- '../../../vite/legacy-polyfills'
+ expect(manifest['../../vite/legacy-polyfills']).toBeDefined()
+ expect(manifest['../../vite/legacy-polyfills'].src).toBe(
+ '../../vite/legacy-polyfills'
)
})
diff --git a/packages/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts b/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts
similarity index 100%
rename from packages/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts
rename to playground/legacy/__tests__/ssr/legacy-ssr.spec.ts
diff --git a/packages/playground/legacy/__tests__/ssr/serve.js b/playground/legacy/__tests__/ssr/serve.js
similarity index 92%
rename from packages/playground/legacy/__tests__/ssr/serve.js
rename to playground/legacy/__tests__/ssr/serve.js
index df43f180afb188..c7ef2ed3520e53 100644
--- a/packages/playground/legacy/__tests__/ssr/serve.js
+++ b/playground/legacy/__tests__/ssr/serve.js
@@ -2,8 +2,9 @@
// this is automtically detected by scripts/jestPerTestSetup.ts and will replace
// the default e2e test serve behavior
const path = require('path')
+const { ports } = require('../../../testUtils')
-const port = (exports.port = 9527)
+const port = (exports.port = ports['legacy/ssr'])
/**
* @param {string} root
diff --git a/packages/playground/legacy/async.js b/playground/legacy/async.js
similarity index 100%
rename from packages/playground/legacy/async.js
rename to playground/legacy/async.js
diff --git a/packages/playground/legacy/entry-server.js b/playground/legacy/entry-server.js
similarity index 100%
rename from packages/playground/legacy/entry-server.js
rename to playground/legacy/entry-server.js
diff --git a/packages/playground/legacy/immutable-chunk.js b/playground/legacy/immutable-chunk.js
similarity index 100%
rename from packages/playground/legacy/immutable-chunk.js
rename to playground/legacy/immutable-chunk.js
diff --git a/packages/playground/legacy/index.html b/playground/legacy/index.html
similarity index 100%
rename from packages/playground/legacy/index.html
rename to playground/legacy/index.html
diff --git a/packages/playground/legacy/main.js b/playground/legacy/main.js
similarity index 100%
rename from packages/playground/legacy/main.js
rename to playground/legacy/main.js
diff --git a/packages/playground/legacy/package.json b/playground/legacy/package.json
similarity index 79%
rename from packages/playground/legacy/package.json
rename to playground/legacy/package.json
index 3a3315c42aa832..f8803564f93f12 100644
--- a/packages/playground/legacy/package.json
+++ b/playground/legacy/package.json
@@ -6,11 +6,11 @@
"dev": "vite",
"build": "vite build --debug legacy",
"build:custom-filename": "vite --config ./vite.config-custom-filename.js build --debug legacy",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"devDependencies": {
"@vitejs/plugin-legacy": "workspace:*",
- "express": "^4.17.1"
+ "express": "^4.18.1"
}
}
diff --git a/packages/playground/legacy/style.css b/playground/legacy/style.css
similarity index 100%
rename from packages/playground/legacy/style.css
rename to playground/legacy/style.css
diff --git a/packages/playground/legacy/vite.config-custom-filename.js b/playground/legacy/vite.config-custom-filename.js
similarity index 100%
rename from packages/playground/legacy/vite.config-custom-filename.js
rename to playground/legacy/vite.config-custom-filename.js
diff --git a/packages/playground/legacy/vite.config.js b/playground/legacy/vite.config.js
similarity index 100%
rename from packages/playground/legacy/vite.config.js
rename to playground/legacy/vite.config.js
diff --git a/packages/playground/lib/__tests__/lib.spec.ts b/playground/lib/__tests__/lib.spec.ts
similarity index 55%
rename from packages/playground/lib/__tests__/lib.spec.ts
rename to playground/lib/__tests__/lib.spec.ts
index 382fb16510ce6f..cc5887c2777fcb 100644
--- a/packages/playground/lib/__tests__/lib.spec.ts
+++ b/playground/lib/__tests__/lib.spec.ts
@@ -9,10 +9,22 @@ if (isBuild) {
test('umd', async () => {
expect(await page.textContent('.umd')).toBe('It works')
+ const code = fs.readFileSync(
+ path.join(testDir, 'dist/my-lib-custom-filename.umd.js'),
+ 'utf-8'
+ )
+ // esbuild helpers are injected inside of the UMD wrapper
+ expect(code).toMatch(/^\(function\(/)
})
test('iife', async () => {
expect(await page.textContent('.iife')).toBe('It works')
+ const code = fs.readFileSync(
+ path.join(testDir, 'dist/my-lib-custom-filename.iife.js'),
+ 'utf-8'
+ )
+ // esbuild helpers are injected inside of the IIFE wrapper
+ expect(code).toMatch(/^var MyLib=function\(\){"use strict";/)
})
test('Library mode does not include `preload`', async () => {
@@ -23,6 +35,13 @@ if (isBuild) {
)
expect(code).not.toMatch('__vitePreload')
})
+
+ test('@import hoist', async () => {
+ serverLogs.forEach((log) => {
+ // no warning from esbuild css minifier
+ expect(log).not.toMatch('All "@import" rules must come first')
+ })
+ })
} else {
test('dev', async () => {
expect(await page.textContent('.demo')).toBe('It works')
diff --git a/packages/playground/lib/__tests__/serve.js b/playground/lib/__tests__/serve.js
similarity index 85%
rename from packages/playground/lib/__tests__/serve.js
rename to playground/lib/__tests__/serve.js
index 15c64de40276d1..2534545de5c221 100644
--- a/packages/playground/lib/__tests__/serve.js
+++ b/playground/lib/__tests__/serve.js
@@ -5,8 +5,11 @@
const path = require('path')
const http = require('http')
const sirv = require('sirv')
+const { ports } = require('../../testUtils')
-const port = (exports.port = 9527)
+const port = (exports.port = ports.lib)
+
+global.serverLogs = []
/**
* @param {string} root
@@ -15,6 +18,8 @@ const port = (exports.port = 9527)
exports.serve = async function serve(root, isBuildTest) {
// build first
+ setupConsoleWarnCollector()
+
if (!isBuildTest) {
const { createServer } = require('vite')
process.env.VITE_INLINE = 'inline-serve'
@@ -54,7 +59,7 @@ exports.serve = async function serve(root, isBuildTest) {
await build({
root,
- logLevel: 'silent',
+ logLevel: 'warn', // output esbuild warns
configFile: path.resolve(__dirname, '../vite.dyimport.config.js')
})
@@ -88,3 +93,11 @@ exports.serve = async function serve(root, isBuildTest) {
})
}
}
+
+function setupConsoleWarnCollector() {
+ const warn = console.warn
+ console.warn = (...args) => {
+ global.serverLogs.push(args.join(' '))
+ return warn.call(console, ...args)
+ }
+}
diff --git a/packages/playground/lib/index.dist.html b/playground/lib/index.dist.html
similarity index 91%
rename from packages/playground/lib/index.dist.html
rename to playground/lib/index.dist.html
index d6273923370aeb..9e0fac1f6b5730 100644
--- a/packages/playground/lib/index.dist.html
+++ b/playground/lib/index.dist.html
@@ -5,7 +5,7 @@
diff --git a/packages/playground/lib/index.html b/playground/lib/index.html
similarity index 100%
rename from packages/playground/lib/index.html
rename to playground/lib/index.html
diff --git a/packages/playground/lib/package.json b/playground/lib/package.json
similarity index 72%
rename from packages/playground/lib/package.json
rename to playground/lib/package.json
index 2c3ae4be3d4bcb..66b827b7c84179 100644
--- a/packages/playground/lib/package.json
+++ b/playground/lib/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
}
}
diff --git a/playground/lib/src/dynamic.css b/playground/lib/src/dynamic.css
new file mode 100644
index 00000000000000..4378c8d328cfbe
--- /dev/null
+++ b/playground/lib/src/dynamic.css
@@ -0,0 +1,4 @@
+@import 'https://cdn.jsdelivr.net/npm/@mdi/font@5.9.55/css/materialdesignicons.min.css';
+.dynamic {
+ color: red;
+}
diff --git a/playground/lib/src/index.css b/playground/lib/src/index.css
new file mode 100644
index 00000000000000..b0bd670bd9ecad
--- /dev/null
+++ b/playground/lib/src/index.css
@@ -0,0 +1,3 @@
+.index {
+ color: blue;
+}
diff --git a/playground/lib/src/main.js b/playground/lib/src/main.js
new file mode 100644
index 00000000000000..cb2fb3b842dc4f
--- /dev/null
+++ b/playground/lib/src/main.js
@@ -0,0 +1,6 @@
+export default function myLib(sel) {
+ // Force esbuild spread helpers (https://github.com/evanw/esbuild/issues/951)
+ console.log({ ...'foo' })
+
+ document.querySelector(sel).textContent = 'It works'
+}
diff --git a/packages/playground/lib/src/main2.js b/playground/lib/src/main2.js
similarity index 73%
rename from packages/playground/lib/src/main2.js
rename to playground/lib/src/main2.js
index 0c729fad8d165c..f19a16bb128949 100644
--- a/packages/playground/lib/src/main2.js
+++ b/playground/lib/src/main2.js
@@ -1,4 +1,9 @@
+import './index.css'
+
export default async function message(sel) {
const message = await import('./message.js')
+
+ await import('./dynamic.css')
+
document.querySelector(sel).textContent = message.default
}
diff --git a/packages/playground/lib/src/message.js b/playground/lib/src/message.js
similarity index 100%
rename from packages/playground/lib/src/message.js
rename to playground/lib/src/message.js
diff --git a/packages/playground/lib/vite.config.js b/playground/lib/vite.config.js
similarity index 89%
rename from packages/playground/lib/vite.config.js
rename to playground/lib/vite.config.js
index 50cd188b1a40cc..72c040d38d6dcf 100644
--- a/packages/playground/lib/vite.config.js
+++ b/playground/lib/vite.config.js
@@ -10,7 +10,7 @@ module.exports = {
entry: path.resolve(__dirname, 'src/main.js'),
name: 'MyLib',
formats: ['es', 'umd', 'iife'],
- fileName: (format) => `my-lib-custom-filename.${format}.js`
+ fileName: 'my-lib-custom-filename'
}
},
plugins: [
diff --git a/packages/playground/lib/vite.dyimport.config.js b/playground/lib/vite.dyimport.config.js
similarity index 94%
rename from packages/playground/lib/vite.dyimport.config.js
rename to playground/lib/vite.dyimport.config.js
index 76311f4b8ba138..d738503f0c9d09 100644
--- a/packages/playground/lib/vite.dyimport.config.js
+++ b/playground/lib/vite.dyimport.config.js
@@ -6,7 +6,6 @@ const path = require('path')
*/
module.exports = {
build: {
- minify: false,
lib: {
entry: path.resolve(__dirname, 'src/main2.js'),
formats: ['es'],
diff --git a/packages/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts b/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts
similarity index 100%
rename from packages/playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts
rename to playground/multiple-entrypoints/__tests__/multiple-entrypoints.spec.ts
diff --git a/packages/playground/multiple-entrypoints/deps.json b/playground/multiple-entrypoints/deps.json
similarity index 100%
rename from packages/playground/multiple-entrypoints/deps.json
rename to playground/multiple-entrypoints/deps.json
diff --git a/packages/playground/multiple-entrypoints/dynamic-a.js b/playground/multiple-entrypoints/dynamic-a.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/dynamic-a.js
rename to playground/multiple-entrypoints/dynamic-a.js
diff --git a/packages/playground/multiple-entrypoints/dynamic-b.js b/playground/multiple-entrypoints/dynamic-b.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/dynamic-b.js
rename to playground/multiple-entrypoints/dynamic-b.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a0.js b/playground/multiple-entrypoints/entrypoints/a0.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a0.js
rename to playground/multiple-entrypoints/entrypoints/a0.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a1.js b/playground/multiple-entrypoints/entrypoints/a1.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a1.js
rename to playground/multiple-entrypoints/entrypoints/a1.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a10.js b/playground/multiple-entrypoints/entrypoints/a10.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a10.js
rename to playground/multiple-entrypoints/entrypoints/a10.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a11.js b/playground/multiple-entrypoints/entrypoints/a11.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a11.js
rename to playground/multiple-entrypoints/entrypoints/a11.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a12.js b/playground/multiple-entrypoints/entrypoints/a12.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a12.js
rename to playground/multiple-entrypoints/entrypoints/a12.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a13.js b/playground/multiple-entrypoints/entrypoints/a13.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a13.js
rename to playground/multiple-entrypoints/entrypoints/a13.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a14.js b/playground/multiple-entrypoints/entrypoints/a14.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a14.js
rename to playground/multiple-entrypoints/entrypoints/a14.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a15.js b/playground/multiple-entrypoints/entrypoints/a15.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a15.js
rename to playground/multiple-entrypoints/entrypoints/a15.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a16.js b/playground/multiple-entrypoints/entrypoints/a16.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a16.js
rename to playground/multiple-entrypoints/entrypoints/a16.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a17.js b/playground/multiple-entrypoints/entrypoints/a17.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a17.js
rename to playground/multiple-entrypoints/entrypoints/a17.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a18.js b/playground/multiple-entrypoints/entrypoints/a18.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a18.js
rename to playground/multiple-entrypoints/entrypoints/a18.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a19.js b/playground/multiple-entrypoints/entrypoints/a19.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a19.js
rename to playground/multiple-entrypoints/entrypoints/a19.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a2.js b/playground/multiple-entrypoints/entrypoints/a2.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a2.js
rename to playground/multiple-entrypoints/entrypoints/a2.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a20.js b/playground/multiple-entrypoints/entrypoints/a20.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a20.js
rename to playground/multiple-entrypoints/entrypoints/a20.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a21.js b/playground/multiple-entrypoints/entrypoints/a21.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a21.js
rename to playground/multiple-entrypoints/entrypoints/a21.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a22.js b/playground/multiple-entrypoints/entrypoints/a22.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a22.js
rename to playground/multiple-entrypoints/entrypoints/a22.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a23.js b/playground/multiple-entrypoints/entrypoints/a23.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a23.js
rename to playground/multiple-entrypoints/entrypoints/a23.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a24.js b/playground/multiple-entrypoints/entrypoints/a24.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a24.js
rename to playground/multiple-entrypoints/entrypoints/a24.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a3.js b/playground/multiple-entrypoints/entrypoints/a3.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a3.js
rename to playground/multiple-entrypoints/entrypoints/a3.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a4.js b/playground/multiple-entrypoints/entrypoints/a4.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a4.js
rename to playground/multiple-entrypoints/entrypoints/a4.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a5.js b/playground/multiple-entrypoints/entrypoints/a5.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a5.js
rename to playground/multiple-entrypoints/entrypoints/a5.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a6.js b/playground/multiple-entrypoints/entrypoints/a6.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a6.js
rename to playground/multiple-entrypoints/entrypoints/a6.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a7.js b/playground/multiple-entrypoints/entrypoints/a7.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a7.js
rename to playground/multiple-entrypoints/entrypoints/a7.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a8.js b/playground/multiple-entrypoints/entrypoints/a8.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a8.js
rename to playground/multiple-entrypoints/entrypoints/a8.js
diff --git a/packages/playground/multiple-entrypoints/entrypoints/a9.js b/playground/multiple-entrypoints/entrypoints/a9.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/entrypoints/a9.js
rename to playground/multiple-entrypoints/entrypoints/a9.js
diff --git a/packages/playground/multiple-entrypoints/index.html b/playground/multiple-entrypoints/index.html
similarity index 100%
rename from packages/playground/multiple-entrypoints/index.html
rename to playground/multiple-entrypoints/index.html
diff --git a/packages/playground/multiple-entrypoints/index.js b/playground/multiple-entrypoints/index.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/index.js
rename to playground/multiple-entrypoints/index.js
diff --git a/packages/playground/multiple-entrypoints/package.json b/playground/multiple-entrypoints/package.json
similarity index 72%
rename from packages/playground/multiple-entrypoints/package.json
rename to playground/multiple-entrypoints/package.json
index 6c338a64518ddb..07818337be7bba 100644
--- a/packages/playground/multiple-entrypoints/package.json
+++ b/playground/multiple-entrypoints/package.json
@@ -5,11 +5,11 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"devDependencies": {
"fast-glob": "^3.2.11",
- "sass": "^1.43.4"
+ "sass": "^1.51.0"
}
}
diff --git a/packages/playground/multiple-entrypoints/reference.js b/playground/multiple-entrypoints/reference.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/reference.js
rename to playground/multiple-entrypoints/reference.js
diff --git a/packages/playground/multiple-entrypoints/reference.scss b/playground/multiple-entrypoints/reference.scss
similarity index 100%
rename from packages/playground/multiple-entrypoints/reference.scss
rename to playground/multiple-entrypoints/reference.scss
diff --git a/packages/playground/multiple-entrypoints/vite.config.js b/playground/multiple-entrypoints/vite.config.js
similarity index 100%
rename from packages/playground/multiple-entrypoints/vite.config.js
rename to playground/multiple-entrypoints/vite.config.js
diff --git a/packages/playground/nested-deps/__tests__/nested-deps.spec.ts b/playground/nested-deps/__tests__/nested-deps.spec.ts
similarity index 100%
rename from packages/playground/nested-deps/__tests__/nested-deps.spec.ts
rename to playground/nested-deps/__tests__/nested-deps.spec.ts
diff --git a/packages/playground/nested-deps/index.html b/playground/nested-deps/index.html
similarity index 100%
rename from packages/playground/nested-deps/index.html
rename to playground/nested-deps/index.html
diff --git a/packages/playground/nested-deps/package.json b/playground/nested-deps/package.json
similarity index 87%
rename from packages/playground/nested-deps/package.json
rename to playground/nested-deps/package.json
index d7450d0545fcb4..cbfcfe44df551b 100644
--- a/packages/playground/nested-deps/package.json
+++ b/playground/nested-deps/package.json
@@ -5,7 +5,7 @@
"scripts": {
"dev": "vite",
"build": "vite build",
- "debug": "node --inspect-brk ../../vite/bin/vite",
+ "debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"dependencies": {
diff --git a/packages/playground/nested-deps/test-package-a/index.js b/playground/nested-deps/test-package-a/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-a/index.js
rename to playground/nested-deps/test-package-a/index.js
diff --git a/packages/playground/nested-deps/test-package-a/package.json b/playground/nested-deps/test-package-a/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-a/package.json
rename to playground/nested-deps/test-package-a/package.json
diff --git a/packages/playground/nested-deps/test-package-b/index.js b/playground/nested-deps/test-package-b/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-b/index.js
rename to playground/nested-deps/test-package-b/index.js
diff --git a/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js b/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js
rename to playground/nested-deps/test-package-b/node_modules/test-package-a/index.js
diff --git a/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json b/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json
rename to playground/nested-deps/test-package-b/node_modules/test-package-a/package.json
diff --git a/packages/playground/nested-deps/test-package-b/package.json b/playground/nested-deps/test-package-b/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-b/package.json
rename to playground/nested-deps/test-package-b/package.json
diff --git a/packages/playground/nested-deps/test-package-c/index-es.js b/playground/nested-deps/test-package-c/index-es.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-c/index-es.js
rename to playground/nested-deps/test-package-c/index-es.js
diff --git a/packages/playground/nested-deps/test-package-c/index.js b/playground/nested-deps/test-package-c/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-c/index.js
rename to playground/nested-deps/test-package-c/index.js
diff --git a/packages/playground/nested-deps/test-package-c/package.json b/playground/nested-deps/test-package-c/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-c/package.json
rename to playground/nested-deps/test-package-c/package.json
diff --git a/packages/playground/nested-deps/test-package-c/side.js b/playground/nested-deps/test-package-c/side.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-c/side.js
rename to playground/nested-deps/test-package-c/side.js
diff --git a/packages/playground/nested-deps/test-package-d/index.js b/playground/nested-deps/test-package-d/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-d/index.js
rename to playground/nested-deps/test-package-d/index.js
diff --git a/packages/playground/nested-deps/test-package-d/package.json b/playground/nested-deps/test-package-d/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-d/package.json
rename to playground/nested-deps/test-package-d/package.json
diff --git a/packages/playground/nested-deps/test-package-d/test-package-d-nested/index.js b/playground/nested-deps/test-package-d/test-package-d-nested/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-d/test-package-d-nested/index.js
rename to playground/nested-deps/test-package-d/test-package-d-nested/index.js
diff --git a/packages/playground/nested-deps/test-package-d/test-package-d-nested/package.json b/playground/nested-deps/test-package-d/test-package-d-nested/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-d/test-package-d-nested/package.json
rename to playground/nested-deps/test-package-d/test-package-d-nested/package.json
diff --git a/packages/playground/nested-deps/test-package-e/index.js b/playground/nested-deps/test-package-e/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-e/index.js
rename to playground/nested-deps/test-package-e/index.js
diff --git a/packages/playground/nested-deps/test-package-e/package.json b/playground/nested-deps/test-package-e/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-e/package.json
rename to playground/nested-deps/test-package-e/package.json
diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-excluded/index.js b/playground/nested-deps/test-package-e/test-package-e-excluded/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-e/test-package-e-excluded/index.js
rename to playground/nested-deps/test-package-e/test-package-e-excluded/index.js
diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-excluded/package.json b/playground/nested-deps/test-package-e/test-package-e-excluded/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-e/test-package-e-excluded/package.json
rename to playground/nested-deps/test-package-e/test-package-e-excluded/package.json
diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-included/index.js b/playground/nested-deps/test-package-e/test-package-e-included/index.js
similarity index 100%
rename from packages/playground/nested-deps/test-package-e/test-package-e-included/index.js
rename to playground/nested-deps/test-package-e/test-package-e-included/index.js
diff --git a/packages/playground/nested-deps/test-package-e/test-package-e-included/package.json b/playground/nested-deps/test-package-e/test-package-e-included/package.json
similarity index 100%
rename from packages/playground/nested-deps/test-package-e/test-package-e-included/package.json
rename to playground/nested-deps/test-package-e/test-package-e-included/package.json
diff --git a/packages/playground/nested-deps/vite.config.js b/playground/nested-deps/vite.config.js
similarity index 100%
rename from packages/playground/nested-deps/vite.config.js
rename to playground/nested-deps/vite.config.js
diff --git a/playground/optimize-deps/.env b/playground/optimize-deps/.env
new file mode 100644
index 00000000000000..995fca4af2ee24
--- /dev/null
+++ b/playground/optimize-deps/.env
@@ -0,0 +1 @@
+NODE_ENV=production
\ No newline at end of file
diff --git a/packages/playground/optimize-deps/.hidden-dir/foo.js b/playground/optimize-deps/.hidden-dir/foo.js
similarity index 100%
rename from packages/playground/optimize-deps/.hidden-dir/foo.js
rename to playground/optimize-deps/.hidden-dir/foo.js
diff --git a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/playground/optimize-deps/__tests__/optimize-deps.spec.ts
similarity index 96%
rename from packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts
rename to playground/optimize-deps/__tests__/optimize-deps.spec.ts
index d95a6d984cd9aa..e832408370969a 100644
--- a/packages/playground/optimize-deps/__tests__/optimize-deps.spec.ts
+++ b/playground/optimize-deps/__tests__/optimize-deps.spec.ts
@@ -62,6 +62,10 @@ test('import * from optimized dep', async () => {
expect(await page.textContent('.import-star')).toMatch(`[success]`)
})
+test('import from dep with process.env.NODE_ENV', async () => {
+ expect(await page.textContent('.node-env')).toMatch(`prod`)
+})
+
test('import from dep with .notjs files', async () => {
expect(await page.textContent('.not-js')).toMatch(`[success]`)
})
diff --git a/packages/playground/optimize-deps/cjs-dynamic.js b/playground/optimize-deps/cjs-dynamic.js
similarity index 100%
rename from packages/playground/optimize-deps/cjs-dynamic.js
rename to playground/optimize-deps/cjs-dynamic.js
diff --git a/packages/playground/optimize-deps/cjs.js b/playground/optimize-deps/cjs.js
similarity index 100%
rename from packages/playground/optimize-deps/cjs.js
rename to playground/optimize-deps/cjs.js
diff --git a/packages/playground/optimize-deps/dedupe.js b/playground/optimize-deps/dedupe.js
similarity index 100%
rename from packages/playground/optimize-deps/dedupe.js
rename to playground/optimize-deps/dedupe.js
diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js b/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js
rename to playground/optimize-deps/dep-cjs-compiled-from-cjs/index.js
diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json b/playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json
similarity index 100%
rename from packages/playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json
rename to playground/optimize-deps/dep-cjs-compiled-from-cjs/package.json
diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-esm/index.js b/playground/optimize-deps/dep-cjs-compiled-from-esm/index.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-cjs-compiled-from-esm/index.js
rename to playground/optimize-deps/dep-cjs-compiled-from-esm/index.js
diff --git a/packages/playground/optimize-deps/dep-cjs-compiled-from-esm/package.json b/playground/optimize-deps/dep-cjs-compiled-from-esm/package.json
similarity index 100%
rename from packages/playground/optimize-deps/dep-cjs-compiled-from-esm/package.json
rename to playground/optimize-deps/dep-cjs-compiled-from-esm/package.json
diff --git a/packages/playground/optimize-deps/dep-esbuild-plugin-transform/index.js b/playground/optimize-deps/dep-esbuild-plugin-transform/index.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-esbuild-plugin-transform/index.js
rename to playground/optimize-deps/dep-esbuild-plugin-transform/index.js
diff --git a/packages/playground/optimize-deps/dep-esbuild-plugin-transform/package.json b/playground/optimize-deps/dep-esbuild-plugin-transform/package.json
similarity index 100%
rename from packages/playground/optimize-deps/dep-esbuild-plugin-transform/package.json
rename to playground/optimize-deps/dep-esbuild-plugin-transform/package.json
diff --git a/packages/playground/optimize-deps/dep-linked-include/Test.vue b/playground/optimize-deps/dep-linked-include/Test.vue
similarity index 100%
rename from packages/playground/optimize-deps/dep-linked-include/Test.vue
rename to playground/optimize-deps/dep-linked-include/Test.vue
diff --git a/packages/playground/optimize-deps/dep-linked-include/foo.js b/playground/optimize-deps/dep-linked-include/foo.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-linked-include/foo.js
rename to playground/optimize-deps/dep-linked-include/foo.js
diff --git a/packages/playground/optimize-deps/dep-linked-include/index.mjs b/playground/optimize-deps/dep-linked-include/index.mjs
similarity index 100%
rename from packages/playground/optimize-deps/dep-linked-include/index.mjs
rename to playground/optimize-deps/dep-linked-include/index.mjs
diff --git a/packages/playground/optimize-deps/dep-linked-include/package.json b/playground/optimize-deps/dep-linked-include/package.json
similarity index 100%
rename from packages/playground/optimize-deps/dep-linked-include/package.json
rename to playground/optimize-deps/dep-linked-include/package.json
diff --git a/packages/playground/optimize-deps/dep-linked-include/test.css b/playground/optimize-deps/dep-linked-include/test.css
similarity index 100%
rename from packages/playground/optimize-deps/dep-linked-include/test.css
rename to playground/optimize-deps/dep-linked-include/test.css
diff --git a/packages/playground/optimize-deps/dep-linked/index.js b/playground/optimize-deps/dep-linked/index.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-linked/index.js
rename to playground/optimize-deps/dep-linked/index.js
diff --git a/packages/playground/optimize-deps/dep-linked/package.json b/playground/optimize-deps/dep-linked/package.json
similarity index 100%
rename from packages/playground/optimize-deps/dep-linked/package.json
rename to playground/optimize-deps/dep-linked/package.json
diff --git a/playground/optimize-deps/dep-node-env/index.js b/playground/optimize-deps/dep-node-env/index.js
new file mode 100644
index 00000000000000..8548c37894539f
--- /dev/null
+++ b/playground/optimize-deps/dep-node-env/index.js
@@ -0,0 +1 @@
+export const env = process.env.NODE_ENV === 'production' ? 'prod' : 'dev'
diff --git a/playground/optimize-deps/dep-node-env/package.json b/playground/optimize-deps/dep-node-env/package.json
new file mode 100644
index 00000000000000..59a00fb153c522
--- /dev/null
+++ b/playground/optimize-deps/dep-node-env/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "dep-node-env",
+ "private": true,
+ "version": "1.0.0"
+}
diff --git a/packages/playground/optimize-deps/dep-not-js/foo.js b/playground/optimize-deps/dep-not-js/foo.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-not-js/foo.js
rename to playground/optimize-deps/dep-not-js/foo.js
diff --git a/packages/playground/optimize-deps/dep-not-js/index.notjs b/playground/optimize-deps/dep-not-js/index.notjs
similarity index 100%
rename from packages/playground/optimize-deps/dep-not-js/index.notjs
rename to playground/optimize-deps/dep-not-js/index.notjs
diff --git a/packages/playground/optimize-deps/dep-not-js/package.json b/playground/optimize-deps/dep-not-js/package.json
similarity index 100%
rename from packages/playground/optimize-deps/dep-not-js/package.json
rename to playground/optimize-deps/dep-not-js/package.json
diff --git a/packages/playground/optimize-deps/dep-with-dynamic-import/dynamic.js b/playground/optimize-deps/dep-with-dynamic-import/dynamic.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-with-dynamic-import/dynamic.js
rename to playground/optimize-deps/dep-with-dynamic-import/dynamic.js
diff --git a/packages/playground/optimize-deps/dep-with-dynamic-import/index.js b/playground/optimize-deps/dep-with-dynamic-import/index.js
similarity index 100%
rename from packages/playground/optimize-deps/dep-with-dynamic-import/index.js
rename to playground/optimize-deps/dep-with-dynamic-import/index.js
diff --git a/packages/playground/optimize-deps/dep-with-dynamic-import/package.json b/playground/optimize-deps/dep-with-dynamic-import/package.json
similarity index 100%
rename from packages/playground/optimize-deps/dep-with-dynamic-import/package.json
rename to playground/optimize-deps/dep-with-dynamic-import/package.json
diff --git a/packages/playground/optimize-deps/glob/foo.js b/playground/optimize-deps/glob/foo.js
similarity index 100%
rename from packages/playground/optimize-deps/glob/foo.js
rename to playground/optimize-deps/glob/foo.js
diff --git a/packages/playground/optimize-deps/index.html b/playground/optimize-deps/index.html
similarity index 94%
rename from packages/playground/optimize-deps/index.html
rename to playground/optimize-deps/index.html
index 2be896d00acba9..d11383bfcb3e04 100644
--- a/packages/playground/optimize-deps/index.html
+++ b/playground/optimize-deps/index.html
@@ -38,6 +38,9 @@
Optimizing force included dep even when it's linked
import * as ...
+
Import from dependency with process.env.NODE_ENV
+
+
Import from dependency with .notjs files
@@ -73,7 +76,7 @@
Reused variable names
`
+const DYNAMIC_STYLES = `
+
+`
+
async function createServer(
root = process.cwd(),
isProd = process.env.NODE_ENV === 'production'
@@ -42,15 +50,30 @@ async function createServer(
// use vite's connect instance as middleware
app.use(vite.middlewares)
- app.use('*', async (req, res) => {
+ app.use('*', async (req, res, next) => {
try {
let [url] = req.originalUrl.split('?')
if (url.endsWith('/')) url += 'index.html'
+ if (url.startsWith('/favicon.ico')) {
+ return res.status(404).end('404')
+ }
+ if (url.startsWith('/@id/__x00__')) {
+ return next()
+ }
+
const htmlLoc = resolve(`.${url}`)
- let html = fs.readFileSync(htmlLoc, 'utf8')
- html = html.replace('