diff --git a/.eslintrc.js b/.eslintrc.js index 0c4baa022a5260..dba020daf5fe2e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -107,6 +107,12 @@ module.exports = defineConfig({ rules: { '@typescript-eslint/explicit-module-boundary-types': 'off' } + }, + { + files: ['*.d.ts'], + rules: { + '@typescript-eslint/triple-slash-reference': 'off' + } } ] }) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 2310f8f92d3b28..00000000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -name: "\U0001F41E Bug report" -about: Report an issue with Vite -title: '' -labels: 'pending triage' -assignees: '' ---- - - - - -### Describe the bug - - - - - -### Reproduction - - - -### System Info - -Output of `npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers`: - -```node - -``` - -Used package manager: - -### Logs - - - -```node - -``` - ---- - -### Before submitting the issue, please make sure you do the following - -- [ ] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/.github/contributing.md). -- [ ] Read the [docs](https://vitejs.dev/guide). -- [ ] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. -- [ ] Provide a description in this issue that describes the bug. -- [ ] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead. -- [ ] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/). diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000000000..af097a821a5f7d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,71 @@ +name: "\U0001F41E Bug report" +description: Report an issue with Vite +labels: [pending triage] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + - type: textarea + id: bug-description + attributes: + label: Describe the bug + description: A clear and concise description of what the bug is. If you intend to submit a PR for this issue, tell us in the description. Thanks! + placeholder: Bug description + validations: + required: true + - type: textarea + id: reproduction + attributes: + label: Reproduction + description: Please provide a link to a repo that can reproduce the problem you ran into. A reproduction is required unless you are absolutely sure that the issue is obvious and the provided information is enough to understand the problem. If a report is vague (e.g. just a generic error message) and has no reproduction, it will receive a "need reproduction" label. If no reproduction is provided after 3 days, it will be auto-closed. + placeholder: Reproduction + validations: + required: true + - type: textarea + id: system-info + attributes: + label: System Info + description: Output of `npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers` + render: shell + placeholder: System, Binaries, Browsers + validations: + required: true + - type: dropdown + id: package-manager + attributes: + label: Used Package Manager + description: Select the used package manager + options: + - npm + - yarn + - pnpm + validations: + required: true + - type: textarea + id: logs + attributes: + label: Logs + description: "Optional if provided reproduction. Please try not to insert an image but copy paste the log text. + + 1. Run `vite` or `vite build` with the `--debug` flag. + 2. Provide the error log here." + render: shell + - type: checkboxes + id: checkboxes + attributes: + label: Validations + description: Before submitting the issue, please make sure you do the following + options: + - label: Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md) + required: true + - label: Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/.github/contributing.md). + required: true + - label: Read the [docs](https://vitejs.dev/guide). + required: true + - label: Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. + required: true + - label: Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead. + required: true + - label: Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/). + required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index c81c77e4875a95..00000000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -name: "\U0001F680 New feature proposal" -about: Propose a new feature to be added to Vite -title: '' -labels: 'enhancement: pending triage' -assignees: '' ---- - -### Clear and concise description of the problem - - - - - -### Suggested solution - - - -### Alternative - - - -### Additional context - - diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 00000000000000..edcb575e71e780 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,46 @@ +name: "\U0001F680 New feature proposal" +description: Propose a new feature to be added to Vite +labels: ["enhancement: pending triage"] +body: + - type: markdown + attributes: + value: | + Thanks for your interest in the project and taking the time to fill out this feature report! + - type: textarea + id: feature-description + attributes: + label: Clear and concise description of the problem + description: "As a developer using Vite I want [goal / wish] so that [benefit]. If you intend to submit a PR for this issue, tell us in the description. Thanks!" + validations: + required: true + - type: textarea + id: suggested-solution + attributes: + label: Suggested solution + description: "In module [xy] we could provide following implementation..." + validations: + required: true + - type: textarea + id: alternative + attributes: + label: Alternative + description: Clear and concise description of any alternative solutions or features you've considered. + - type: textarea + id: additional-context + attributes: + label: Additional context + description: Any other context or screenshots about the feature request here. + - type: checkboxes + id: checkboxes + attributes: + label: Validations + description: Before submitting the issue, please make sure you do the following + options: + - label: Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md) + required: true + - label: Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/.github/contributing.md). + required: true + - label: Read the [docs](https://vitejs.dev/guide). + required: true + - label: Check that there isn't already an issue that request the same feature to avoid creating a duplicate. + required: true diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 79962576c1e16f..703efdf217c79c 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -12,7 +12,6 @@ "pin": false, "rangeStrategy": "bump", "node": false, - "stabilityDays": 7, "ignoreDeps": [ // manually bumping "esbuild", diff --git a/docs/config/index.md b/docs/config/index.md index cdd5740cdfdcb0..3108f3df431023 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -15,7 +15,7 @@ export default { } ``` -Note Vite supports using ES modules syntax in the config file even if the project is not using native Node ESM via `type: "module"`. In this case the config file is auto pre-processed before load. +Note Vite supports using ES modules syntax in the config file even if the project is not using native Node ESM via `type: "module"`. In this case, the config file is auto pre-processed before load. You can also explicitly specify a config file to use with the `--config` CLI option (resolved relative to `cwd`): @@ -38,7 +38,7 @@ const config = { export default config ``` -Alternatively you can use the `defineConfig` helper which should provide intellisense without the need for jsdoc annotations: +Alternatively, you can use the `defineConfig` helper which should provide intellisense without the need for jsdoc annotations: ```js import { defineConfig } from 'vite' @@ -88,7 +88,7 @@ export default async ({ command, mode }) => { - **Type:** `string` - **Default:** `process.cwd()` - Project root directory (where `index.html` is located). Can be an absolute path, or a path relative from the location of the config file itself. + Project root directory (where `index.html` is located). Can be an absolute path, or a path relative to the location of the config file itself. See [Project Root](/guide/#index-html-and-project-root) for more details. @@ -124,7 +124,7 @@ export default async ({ command, mode }) => { - Replacements are performed only when the match is surrounded by word boundaries (`\b`). - Because it's implemented as straightforward text replacements without any syntax analyzation, we recommend using `define` for CONSTANTS only. + Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only. For example, `process.env.FOO` and `__APP_VERSION__` are good fits. But `process` or `global` should not be put into this option. Variables can be shimmed or polyfilled instead. @@ -136,11 +136,13 @@ export default async ({ command, mode }) => { ### publicDir -- **Type:** `string` +- **Type:** `string | false` - **Default:** `"public"` Directory to serve as plain static assets. Files in this directory are served at `/` during dev and copied to the root of `outDir` during build, and are always served or copied as-is without transform. The value can be either an absolute file system path or a path relative to project root. + Defining `publicDir` as `false` disables this feature. + See [The `public` Directory](/guide/assets#the-public-directory) for more details. ### cacheDir @@ -148,7 +150,7 @@ export default async ({ command, mode }) => { - **Type:** `string` - **Default:** `"node_modules/.vite"` - Directory to save cache files. Files in this directory are pre-bundled deps or some other cache files that generated by vite, which can improve the performance. You can use `--force` flag or manually delete the directory to regenerate the cache files. The value can be either an absolute file system path or a path relative to project root. + Directory to save cache files. Files in this directory are pre-bundled deps or some other cache files generated by vite, which can improve the performance. You can use `--force` flag or manually delete the directory to regenerate the cache files. The value can be either an absolute file system path or a path relative to project root. ### resolve.alias @@ -282,7 +284,7 @@ export default async ({ command, mode }) => { } ``` - By default, ESBuild is applied to `ts`, `jsx` and `tsx` files. You can customize this with `esbuild.include` and `esbuild.exclude`, both of which expects type of `string | RegExp | (string | RegExp)[]`. + By default, ESBuild is applied to `ts`, `jsx` and `tsx` files. You can customize this with `esbuild.include` and `esbuild.exclude`, both of which expect type of `string | RegExp | (string | RegExp)[]`. In addition, you can also use `esbuild.jsxInject` to automatically inject JSX helper imports for every file transformed by ESBuild: @@ -367,7 +369,7 @@ export default async ({ command, mode }) => { - **Type:** `boolean | string` - Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname. + Automatically open the app in the browser on server start. When the value is a string, it will be used as the URL's pathname. If you want to open the server in a specific browser you like, you can set the env `process.env.BROWSER` (e.g. `firefox`). See [the `open` package](https://github.com/sindresorhus/open#app) for more details. **Example:** @@ -383,7 +385,7 @@ export default async ({ command, mode }) => { - **Type:** `Record` - Configure custom proxy rules for the dev server. Expects an object of `{ key: options }` pairs. If the key starts with `^`, it will be interpreted as a `RegExp`. + Configure custom proxy rules for the dev server. Expects an object of `{ key: options }` pairs. If the key starts with `^`, it will be interpreted as a `RegExp`. The `configure` option can be used to access the proxy instance. Uses [`http-proxy`](https://github.com/http-party/node-http-proxy). Full options [here](https://github.com/http-party/node-http-proxy#options). @@ -406,6 +408,14 @@ export default async ({ command, mode }) => { target: 'http://jsonplaceholder.typicode.com', changeOrigin: true, rewrite: (path) => path.replace(/^\/fallback/, '') + }, + // Using the proxy instance + '/api': { + target: 'http://jsonplaceholder.typicode.com', + changeOrigin: true, + configure: (proxy, options) => { + // proxy will be an instance of 'http-proxy' + }), } } } @@ -480,7 +490,7 @@ async function createServer() { createServer() ``` -### server.fsServe.strict +### server.fs.strict - **Experimental** - **Type:** `boolean` @@ -488,12 +498,12 @@ createServer() Restrict serving files outside of workspace root. -### server.fsServe.root +### server.fs.allow - **Experimental** -- **Type:** `string` +- **Type:** `string[]` - Restrict files that could be served via `/@fs/`. When `server.fsServe.strict` is set to `true`, accessing files outside this directory will result in a 403. + Restrict files that could be served via `/@fs/`. When `server.fs.strict` is set to `true`, accessing files outside this directory list will result in a 403. Vite will search for the root of the potential workspace and use it as default. A valid workspace met the following conditions, otherwise will fallback to the [project root](/guide/#index-html-and-project-root). @@ -506,9 +516,11 @@ createServer() ```js export default { server: { - fsServe: { + fs: { // Allow serving files from one level up to the project root - root: '..' + allow: [ + '..' + ] } } } @@ -603,6 +615,12 @@ createServer() Options to pass on to [@rollup/plugin-commonjs](https://github.com/rollup/plugins/tree/master/packages/commonjs). +### build.dynamicImportVarsOptions + +- **Type:** [`RollupDynamicImportVarsOptions`](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#options) + + Options to pass on to [@rollup/plugin-dynamic-import-vars](https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars). + ### build.lib - **Type:** `{ entry: string, name?: string, formats?: ('es' | 'cjs' | 'umd' | 'iife')[], fileName?: string }` @@ -616,14 +634,14 @@ createServer() - **Default:** `false` - **Related:** [Backend Integration](/guide/backend-integration) - When set to `true`, the build will also generate a `manifest.json` file that contains mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. + When set to `true`, the build will also generate a `manifest.json` file that contains a mapping of non-hashed asset filenames to their hashed versions, which can then be used by a server framework to render the correct asset links. ### build.minify - **Type:** `boolean | 'terser' | 'esbuild'` - **Default:** `'terser'` - Set to `false` to disable minification, or specify the minifier to use. The default is [Terser](https://github.com/terser/terser) which is slower but produces smaller bundles in most cases. Esbuild minification is significantly faster, but will result in slightly larger bundles. + Set to `false` to disable minification, or specify the minifier to use. The default is [Terser](https://github.com/terser/terser) which is slower but produces smaller bundles in most cases. Esbuild minification is significantly faster but will result in slightly larger bundles. ### build.terserOptions @@ -690,6 +708,10 @@ createServer() Dependencies to exclude from pre-bundling. + :::warning CommonJS + CommonJS dependencies should not be excluded from optimization. If an ESM dependency has a nested CommonJS dependency, it should not be excluded as well. + ::: + ### optimizeDeps.include - **Type:** `string[]` @@ -721,7 +743,7 @@ SSR options may be adjusted in minor releases. ### ssr.noExternal -- **Type:** `string[]` +- **Type:** `string | RegExp | (string | RegExp)[]` Prevent listed dependencies from being externalized for SSR. diff --git a/docs/guide/api-hmr.md b/docs/guide/api-hmr.md index 829c53a7f1ccc3..4203e310c63ce9 100644 --- a/docs/guide/api-hmr.md +++ b/docs/guide/api-hmr.md @@ -112,4 +112,13 @@ For now, calling `import.meta.hot.invalidate()` simply reloads the page. ## `hot.on(event, cb)` -Listen to a custom HMR event. Custom HMR events can be sent from plugins. See [handleHotUpdate](./api-plugin#handlehotupdate) for more details. +Listen to an HMR event. + +The following HMR events are dispatched by Vite automatically: +- `'vite:beforeUpdate'` when an update is about to be applied (e.g. a module will be replaced) +- `'vite:beforeFullReload'` when a full reload is about to occur +- `'vite:beforePrune'` when modules that are no longer needed are about to be pruned +- `'vite:error'` when an error occurs (e.g. syntax error) + +Custom HMR events can also be sent from plugins. See [handleHotUpdate](./api-plugin#handlehotupdate) for more details. + diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md index 879e3a2aa0e4f9..d918a19ac66f6b 100644 --- a/docs/guide/api-plugin.md +++ b/docs/guide/api-plugin.md @@ -150,7 +150,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo ### `config` - **Type:** `(config: UserConfig, env: { mode: string, command: string }) => UserConfig | null | void` -- **Kind:** `sync`, `sequential` +- **Kind:** `async`, `sequential` Modify Vite config before it's resolved. The hook receives the raw user config (CLI options merged with config file) and the current config env which exposes the `mode` and `command` being used. It can return a partial config object that will be deeply merged into existing config, or directly mutate the config (if the default merging cannot achieve the desired result). diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index 4d92ee03b36a6d..85ff820b1d05db 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -24,7 +24,7 @@ It will also replace these strings appearing in JavaScript strings and Vue templ ## `.env` Files -Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envDir): +Vite uses [dotenv](https://github.com/motdotla/dotenv) to load additional environment variables from the following files in your [environment directory](/config/#envdir): ``` .env # loaded in all cases diff --git a/docs/guide/using-plugins.md b/docs/guide/using-plugins.md index 79b9b8a66188da..3e14364532bfa9 100644 --- a/docs/guide/using-plugins.md +++ b/docs/guide/using-plugins.md @@ -33,7 +33,7 @@ Falsy plugins will be ignored, which can be used to easily activate or deactivat 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 the [Plugins section](../plugins) for information about official plugins. Community plugins are listed in [awesome-vite](https://github.com/vitejs/awesome-vite#plugins). For compatible Rollup plugins, check out [Vite Rollup Plugins](https://vite-rollup-plugins.patak.dev) for a list of compatible official Rollup plugins with usage instructions or the [Rollup Plugin Compatibility section](../guide/api-plugin#rollup-plugin-compatibility) in case it is not listed there. +Check out the [Plugins section](../plugins/) for information about official plugins. Community plugins are listed in [awesome-vite](https://github.com/vitejs/awesome-vite#plugins). For compatible Rollup plugins, check out [Vite Rollup Plugins](https://vite-rollup-plugins.patak.dev) for a list of compatible official Rollup plugins with usage instructions or the [Rollup Plugin Compatibility section](../guide/api-plugin#rollup-plugin-compatibility) in case it is not listed there. You can also find plugins that follow the [recommended conventions](./api-plugin.md#conventions) using a [npm search for vite-plugin](https://www.npmjs.com/search?q=vite-plugin&ranking=popularity) for Vite plugins or a [npm search for rollup-plugin](https://www.npmjs.com/search?q=rollup-plugin&ranking=popularity) or a [npm search for vite-plugin](https://www.npmjs.com/search?q=vite-plugin&ranking=popularity) for Rollup plugins. diff --git a/package.json b/package.json index 060737c16c16cf..995e488447ee08 100644 --- a/package.json +++ b/package.json @@ -30,31 +30,31 @@ "@types/jest": "^26.0.23", "@types/node": "^15.12.2", "@types/semver": "^7.3.6", - "@typescript-eslint/eslint-plugin": "^4.27.0", - "@typescript-eslint/parser": "^4.27.0", + "@typescript-eslint/eslint-plugin": "^4.28.1", + "@typescript-eslint/parser": "^4.28.1", "chalk": "^4.1.1", "conventional-changelog-cli": "^2.1.1", "cross-env": "^7.0.3", - "eslint": "^7.28.0", + "eslint": "^7.29.0", "eslint-define-config": "^1.0.8", "eslint-plugin-node": "^11.1.0", "execa": "^5.1.1", "fs-extra": "^10.0.0", - "jest": "^27.0.4", + "jest": "^27.0.6", "lint-staged": "^11.0.0", "minimist": "^1.2.5", "node-fetch": "^2.6.1", "npm-run-all": "^4.1.5", - "playwright-chromium": "^1.12.2", - "prettier": "2.3.1", + "playwright-chromium": "^1.12.3", + "prettier": "2.3.2", "prompts": "^2.4.1", "rimraf": "^3.0.2", "semver": "^7.3.5", "sirv": "^1.0.12", "ts-jest": "^27.0.3", "ts-node": "^10.0.0", - "typescript": "^4.3.2", - "vitepress": "^0.15.3", + "typescript": "^4.3.4", + "vitepress": "^0.15.5", "yorkie": "^2.0.0" }, "gitHooks": { diff --git a/packages/create-app/CHANGELOG.md b/packages/create-app/CHANGELOG.md index e376bd65541ec0..e9c63c7fb5dae8 100644 --- a/packages/create-app/CHANGELOG.md +++ b/packages/create-app/CHANGELOG.md @@ -1,3 +1,12 @@ +## [2.4.5](https://github.com/vitejs/vite/compare/create-app@2.4.4...create-app@2.4.5) (2021-07-05) + + +### Bug Fixes + +* **deps:** update all non-major dependencies ([#3878](https://github.com/vitejs/vite/issues/3878)) ([a66a805](https://github.com/vitejs/vite/commit/a66a8053e9520d20bcf95fce870570c5195bcc91)) + + + ## [2.4.4](https://github.com/vitejs/vite/compare/create-app@2.4.3...create-app@2.4.4) (2021-06-22) diff --git a/packages/create-app/package.json b/packages/create-app/package.json index 709957afb55c16..3af7701fbd0539 100644 --- a/packages/create-app/package.json +++ b/packages/create-app/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/create-app", - "version": "2.4.4", + "version": "2.4.5", "license": "MIT", "author": "Evan You", "bin": { @@ -29,7 +29,7 @@ }, "homepage": "https://github.com/vitejs/vite/tree/main/packages/create-app#readme", "dependencies": { - "kolorist": "^1.4.1", + "kolorist": "^1.5.0", "minimist": "^1.2.5", "prompts": "^2.4.1" } diff --git a/packages/create-app/template-lit-element-ts/package.json b/packages/create-app/template-lit-element-ts/package.json index 9a2252302e94e7..af310b0cb83ede 100644 --- a/packages/create-app/template-lit-element-ts/package.json +++ b/packages/create-app/template-lit-element-ts/package.json @@ -18,7 +18,7 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.3.8", + "vite": "^2.4.0", "typescript": "^4.3.2" } } \ No newline at end of file diff --git a/packages/create-app/template-lit-element/package.json b/packages/create-app/template-lit-element/package.json index bfdfe34dfc0572..1b878f04140dfb 100644 --- a/packages/create-app/template-lit-element/package.json +++ b/packages/create-app/template-lit-element/package.json @@ -16,6 +16,6 @@ "lit-element": "^2.4.0" }, "devDependencies": { - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-preact-ts/package.json b/packages/create-app/template-preact-ts/package.json index 756f03e7564f8e..4306b0c9ed3258 100644 --- a/packages/create-app/template-preact-ts/package.json +++ b/packages/create-app/template-preact-ts/package.json @@ -12,6 +12,6 @@ "devDependencies": { "@preact/preset-vite": "^2.0.0", "typescript": "^4.3.2", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-preact/package.json b/packages/create-app/template-preact/package.json index d7413838311e10..2b6f9b32d4a1c8 100644 --- a/packages/create-app/template-preact/package.json +++ b/packages/create-app/template-preact/package.json @@ -11,6 +11,6 @@ }, "devDependencies": { "@preact/preset-vite": "^2.0.0", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-react-ts/package.json b/packages/create-app/template-react-ts/package.json index d40e494e897349..d6e696bf37f176 100644 --- a/packages/create-app/template-react-ts/package.json +++ b/packages/create-app/template-react-ts/package.json @@ -15,6 +15,6 @@ "@types/react-dom": "^17.0.0", "@vitejs/plugin-react-refresh": "^1.3.1", "typescript": "^4.3.2", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-react/package.json b/packages/create-app/template-react/package.json index 9581ef463f066e..47d71d12a4e52f 100644 --- a/packages/create-app/template-react/package.json +++ b/packages/create-app/template-react/package.json @@ -12,6 +12,6 @@ }, "devDependencies": { "@vitejs/plugin-react-refresh": "^1.3.1", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-svelte-ts/package.json b/packages/create-app/template-svelte-ts/package.json index 6e2122a30fbe74..d7876aa51a784f 100644 --- a/packages/create-app/template-svelte-ts/package.json +++ b/packages/create-app/template-svelte-ts/package.json @@ -16,6 +16,6 @@ "svelte-preprocess": "^4.7.2", "tslib": "^2.2.0", "typescript": "^4.3.2", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-svelte/package.json b/packages/create-app/template-svelte/package.json index 59fbee6da09719..5dd47d42553dc7 100644 --- a/packages/create-app/template-svelte/package.json +++ b/packages/create-app/template-svelte/package.json @@ -10,6 +10,6 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "^1.0.0-next.11", "svelte": "^3.37.0", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-vanilla-ts/package.json b/packages/create-app/template-vanilla-ts/package.json index ef9d96ea025360..98f5fc7a71390d 100644 --- a/packages/create-app/template-vanilla-ts/package.json +++ b/packages/create-app/template-vanilla-ts/package.json @@ -8,6 +8,6 @@ }, "devDependencies": { "typescript": "^4.3.2", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-vanilla/package.json b/packages/create-app/template-vanilla/package.json index f97e7ad668535e..d8cf61473eaf61 100644 --- a/packages/create-app/template-vanilla/package.json +++ b/packages/create-app/template-vanilla/package.json @@ -7,6 +7,6 @@ "serve": "vite preview" }, "devDependencies": { - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/create-app/template-vue-ts/package.json b/packages/create-app/template-vue-ts/package.json index 5629b01c27449c..9f1fd123ef914f 100644 --- a/packages/create-app/template-vue-ts/package.json +++ b/packages/create-app/template-vue-ts/package.json @@ -10,10 +10,10 @@ "vue": "^3.0.5" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.2.3", + "@vitejs/plugin-vue": "^1.2.4", "@vue/compiler-sfc": "^3.0.5", "typescript": "^4.3.2", - "vite": "^2.3.8", + "vite": "^2.4.0", "vue-tsc": "^0.0.24" } } \ No newline at end of file diff --git a/packages/create-app/template-vue/package.json b/packages/create-app/template-vue/package.json index 524d95c537200b..82273c37a27f37 100644 --- a/packages/create-app/template-vue/package.json +++ b/packages/create-app/template-vue/package.json @@ -10,8 +10,8 @@ "vue": "^3.0.5" }, "devDependencies": { - "@vitejs/plugin-vue": "^1.2.3", + "@vitejs/plugin-vue": "^1.2.4", "@vue/compiler-sfc": "^3.0.5", - "vite": "^2.3.8" + "vite": "^2.4.0" } } \ No newline at end of file diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts index 944c5a72f4cecc..8025d5766656b5 100644 --- a/packages/playground/css/__tests__/css.spec.ts +++ b/packages/playground/css/__tests__/css.spec.ts @@ -242,3 +242,27 @@ test('PostCSS dir-dependency', async () => { await untilUpdated(() => getColor(el2), 'black') } }) + +test('Url separation', async () => { + const urlSeparated = await page.$('.url-separated') + const baseUrl = 'url(images/dog.webp)' + const cases = new Array(5) + .fill('') + .flatMap((_, i) => + [',', ' ,', ', ', ' , '].map( + (sep) => `background-image:${new Array(i + 1).fill(baseUrl).join(sep)};` + ) + ) + + // Insert the base case + cases.unshift('background-image:url(images/cat.webp),url(images/dog.webp)') + + for (const [c, i] of cases.map((c, i) => [c, i]) as [string, number][]) { + // Replace the previous case + if (i > 0) editFile('imported.css', (code) => code.replace(cases[i - 1], c)) + + expect(await getBg(urlSeparated)).toMatch( + /^url\(.+\)(?:\s*,\s*url\(.+\))*$/ + ) + } +}) diff --git a/packages/playground/css/imported.css b/packages/playground/css/imported.css index 4bedd02a53f0f5..4f89b64b7454fe 100644 --- a/packages/playground/css/imported.css +++ b/packages/playground/css/imported.css @@ -17,3 +17,8 @@ pre { color: pink; } } + +/* test url comma separation */ +.url-separated { + background-image:url(images/cat.webp),url(images/dog.webp); +} \ No newline at end of file diff --git a/packages/playground/css/index.html b/packages/playground/css/index.html index 0a074e8711977b..306f2c5169599c 100644 --- a/packages/playground/css/index.html +++ b/packages/playground/css/index.html @@ -82,6 +82,10 @@

CSS

PostCSS dir-dependency (file 2): this should be grey too

+ +

+ Url separation preservation: should have valid background-image +

diff --git a/packages/playground/data-uri/index.html b/packages/playground/data-uri/index.html index 80e0fc6fcc6c17..32cc458940e60c 100644 --- a/packages/playground/data-uri/index.html +++ b/packages/playground/data-uri/index.html @@ -3,8 +3,12 @@ diff --git a/packages/playground/fs-serve/__tests__/fs-serve.spec.ts b/packages/playground/fs-serve/__tests__/fs-serve.spec.ts new file mode 100644 index 00000000000000..af09045be48b1a --- /dev/null +++ b/packages/playground/fs-serve/__tests__/fs-serve.spec.ts @@ -0,0 +1,32 @@ +import { isBuild } from '../../testUtils' + +const json = require('../safe.json') +const stringified = JSON.stringify(json) + +if (!isBuild) { + test('default import', async () => { + expect(await page.textContent('.full')).toBe(stringified) + }) + + test('named import', async () => { + expect(await page.textContent('.named')).toBe(json.msg) + }) + + test('safe fetch', async () => { + expect(await page.textContent('.safe-fetch')).toBe(stringified) + expect(await page.textContent('.safe-fetch-status')).toBe('200') + }) + + test('unsafe fetch', async () => { + expect(await page.textContent('.unsafe-fetch')).toBe('') + expect(await page.textContent('.unsafe-fetch-status')).toBe('403') + }) + + test('nested entry', async () => { + expect(await page.textContent('.nested-entry')).toBe('foobar') + }) +} else { + test('dummy test to make jest happy', async () => { + // Your test suite must contain at least one test. + }) +} diff --git a/packages/playground/fs-serve/entry.js b/packages/playground/fs-serve/entry.js new file mode 100644 index 00000000000000..b133236e632f16 --- /dev/null +++ b/packages/playground/fs-serve/entry.js @@ -0,0 +1,5 @@ +import { msg } from './nested/foo' + +export const fullmsg = msg + 'bar' + +document.querySelector('.nested-entry').textContent = fullmsg diff --git a/packages/playground/fs-serve/nested/foo.js b/packages/playground/fs-serve/nested/foo.js new file mode 100644 index 00000000000000..4eeb2ac0e1dbb4 --- /dev/null +++ b/packages/playground/fs-serve/nested/foo.js @@ -0,0 +1 @@ +export const msg = 'foo' diff --git a/packages/playground/fs-serve/package.json b/packages/playground/fs-serve/package.json new file mode 100644 index 00000000000000..7f517900a229be --- /dev/null +++ b/packages/playground/fs-serve/package.json @@ -0,0 +1,11 @@ +{ + "name": "test-fs-serve", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "vite root", + "build": "vite build root", + "debug": "node --inspect-brk ../../vite/bin/vite", + "serve": "vite preview" + } +} diff --git a/packages/playground/fs-serve/root/index.html b/packages/playground/fs-serve/root/index.html new file mode 100644 index 00000000000000..1f100557ba3e5b --- /dev/null +++ b/packages/playground/fs-serve/root/index.html @@ -0,0 +1,49 @@ +

Normal Import

+

+

+
+

Safe Fetch

+

+

+
+

Unsafe Fetch

+

+

+
+

Nested Entry

+

+
+
diff --git a/packages/playground/fs-serve/root/vite.config.js b/packages/playground/fs-serve/root/vite.config.js
new file mode 100644
index 00000000000000..1ae96c3d1f7350
--- /dev/null
+++ b/packages/playground/fs-serve/root/vite.config.js
@@ -0,0 +1,19 @@
+const path = require('path')
+
+/**
+ * @type {import('vite').UserConfig}
+ */
+module.exports = {
+  server: {
+    fs: {
+      strict: true,
+      allow: [__dirname]
+    },
+    hmr: {
+      overlay: false
+    }
+  },
+  define: {
+    ROOT: JSON.stringify(path.dirname(__dirname).replace(/\\/g, '/'))
+  }
+}
diff --git a/packages/playground/fs-serve/safe.json b/packages/playground/fs-serve/safe.json
new file mode 100644
index 00000000000000..84f96593c10bad
--- /dev/null
+++ b/packages/playground/fs-serve/safe.json
@@ -0,0 +1,3 @@
+{
+  "msg": "safe"
+}
diff --git a/packages/playground/fs-serve/unsafe.json b/packages/playground/fs-serve/unsafe.json
new file mode 100644
index 00000000000000..9b26fb7a8959fb
--- /dev/null
+++ b/packages/playground/fs-serve/unsafe.json
@@ -0,0 +1,3 @@
+{
+  "msg": "unsafe"
+}
diff --git a/packages/playground/hmr/__tests__/hmr.spec.ts b/packages/playground/hmr/__tests__/hmr.spec.ts
index 403610e8c9d76f..d0c78d9ee3f9f0 100644
--- a/packages/playground/hmr/__tests__/hmr.spec.ts
+++ b/packages/playground/hmr/__tests__/hmr.spec.ts
@@ -20,6 +20,7 @@ if (!isBuild) {
     await untilUpdated(() => el.textContent(), '2')
 
     expect(browserLogs).toMatchObject([
+      '>>> vite:beforeUpdate -- update',
       'foo was: 1',
       '(self-accepting 1) foo is now: 2',
       '(self-accepting 2) foo is now: 2',
@@ -31,6 +32,7 @@ if (!isBuild) {
     await untilUpdated(() => el.textContent(), '3')
 
     expect(browserLogs).toMatchObject([
+      '>>> vite:beforeUpdate -- update',
       'foo was: 2',
       '(self-accepting 1) foo is now: 3',
       '(self-accepting 2) foo is now: 3',
@@ -48,6 +50,7 @@ if (!isBuild) {
     await untilUpdated(() => el.textContent(), '2')
 
     expect(browserLogs).toMatchObject([
+      '>>> vite:beforeUpdate -- update',
       '(dep) foo was: 1',
       '(dep) foo from dispose: 1',
       '(single dep) foo is now: 2',
@@ -64,6 +67,7 @@ if (!isBuild) {
     await untilUpdated(() => el.textContent(), '3')
 
     expect(browserLogs).toMatchObject([
+      '>>> vite:beforeUpdate -- update',
       '(dep) foo was: 2',
       '(dep) foo from dispose: 2',
       '(single dep) foo is now: 3',
@@ -84,6 +88,7 @@ if (!isBuild) {
     await untilUpdated(() => el.textContent(), '2')
 
     expect(browserLogs).toMatchObject([
+      '>>> vite:beforeUpdate -- update',
       '(dep) foo was: 3',
       '(dep) foo from dispose: 3',
       '(single dep) foo is now: 3',
@@ -100,6 +105,7 @@ if (!isBuild) {
     await untilUpdated(() => el.textContent(), '3')
 
     expect(browserLogs).toMatchObject([
+      '>>> vite:beforeUpdate -- update',
       '(dep) foo was: 3',
       '(dep) foo from dispose: 3',
       '(single dep) foo is now: 3',
diff --git a/packages/playground/hmr/hmr.js b/packages/playground/hmr/hmr.js
index 0df01dbee0f5d0..e8da1ecbabf98b 100644
--- a/packages/playground/hmr/hmr.js
+++ b/packages/playground/hmr/hmr.js
@@ -33,6 +33,14 @@ if (import.meta.hot) {
     console.log(`foo was:`, foo)
   })
 
+  import.meta.hot.on('vite:beforeUpdate', (event) => {
+    console.log(`>>> vite:beforeUpdate -- ${event.type}`)
+  })
+
+  import.meta.hot.on('vite:error', (event) => {
+    console.log(`>>> vite:error -- ${event.type}`)
+  })
+
   import.meta.hot.on('foo', ({ msg }) => {
     text('.custom', msg)
   })
diff --git a/packages/playground/legacy/main.js b/packages/playground/legacy/main.js
index c337989413a081..78322d69455af0 100644
--- a/packages/playground/legacy/main.js
+++ b/packages/playground/legacy/main.js
@@ -14,17 +14,19 @@ if (import.meta.env.LEGACY) {
   if (import.meta.env.LEGACY === false) isLegacy = false
 }
 
-document.getElementById('env').textContent = `is legacy: ${isLegacy}`
+text('#env', `is legacy: ${isLegacy}`)
 
 // Iterators
-
-document.getElementById('iterators').textContent = [...new Set(['hello'])].join(
-  ''
-)
+text('#iterators', [...new Set(['hello'])].join(''))
 
 // babel-helpers
-
-document.getElementById('babel-helpers').textContent =
-  // Using `String.raw` to inject `@babel/plugin-transform-template-literals`
-  // helpers.
+// Using `String.raw` to inject `@babel/plugin-transform-template-literals`
+// helpers.
+text(
+  '#babel-helpers',
   String.raw`exposed babel helpers: ${window._templateObject != null}`
+)
+
+function text(el, text) {
+  document.querySelector(el).textContent = text
+}
diff --git a/packages/playground/nested-deps/__tests__/nested-deps.spec.ts b/packages/playground/nested-deps/__tests__/nested-deps.spec.ts
new file mode 100644
index 00000000000000..4db6a5fc9406d8
--- /dev/null
+++ b/packages/playground/nested-deps/__tests__/nested-deps.spec.ts
@@ -0,0 +1,6 @@
+// TODO: Rework #3753, taking into account issues with #4005, #4012, #4014
+test.skip('handle nested package', async () => {
+  expect(await page.textContent('.a')).toBe('A@2.0.0')
+  expect(await page.textContent('.b')).toBe('B@1.0.0')
+  expect(await page.textContent('.nested-a')).toBe('A@1.0.0')
+})
diff --git a/packages/playground/nested-deps/index.html b/packages/playground/nested-deps/index.html
new file mode 100644
index 00000000000000..9759e87db4df54
--- /dev/null
+++ b/packages/playground/nested-deps/index.html
@@ -0,0 +1,21 @@
+

direct dependency A

+

+
+

direct dependency B

+

+
+

nested dependency A

+

+
+
diff --git a/packages/playground/nested-deps/package.json b/packages/playground/nested-deps/package.json
new file mode 100644
index 00000000000000..5c9c814a5252a6
--- /dev/null
+++ b/packages/playground/nested-deps/package.json
@@ -0,0 +1,15 @@
+{
+  "name": "@test/nested-deps",
+  "private": true,
+  "version": "0.0.0",
+  "scripts": {
+    "dev": "vite",
+    "build": "vite build",
+    "debug": "node --inspect-brk ../../vite/bin/vite",
+    "serve": "vite preview"
+  },
+  "dependencies": {
+    "test-package-a": "link:./test-package-a",
+    "test-package-b": "link:./test-package-b"
+  }
+}
diff --git a/packages/playground/nested-deps/test-package-a/index.js b/packages/playground/nested-deps/test-package-a/index.js
new file mode 100644
index 00000000000000..1006df3cf11913
--- /dev/null
+++ b/packages/playground/nested-deps/test-package-a/index.js
@@ -0,0 +1 @@
+export default 'A@2.0.0'
diff --git a/packages/playground/nested-deps/test-package-a/package.json b/packages/playground/nested-deps/test-package-a/package.json
new file mode 100644
index 00000000000000..5055f3dd623043
--- /dev/null
+++ b/packages/playground/nested-deps/test-package-a/package.json
@@ -0,0 +1,5 @@
+{
+  "name": "test-package-a",
+  "version": "2.0.0",
+  "main": "index.js"
+}
diff --git a/packages/playground/nested-deps/test-package-b/index.js b/packages/playground/nested-deps/test-package-b/index.js
new file mode 100644
index 00000000000000..e61d484f4f3b10
--- /dev/null
+++ b/packages/playground/nested-deps/test-package-b/index.js
@@ -0,0 +1,3 @@
+export { default as A } from 'test-package-a'
+
+export default 'B@1.0.0'
diff --git a/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js b/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js
new file mode 100644
index 00000000000000..8b21e17752a5a6
--- /dev/null
+++ b/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/index.js
@@ -0,0 +1 @@
+export default 'A@1.0.0'
diff --git a/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json b/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json
new file mode 100644
index 00000000000000..ce18862474971d
--- /dev/null
+++ b/packages/playground/nested-deps/test-package-b/node_modules/test-package-a/package.json
@@ -0,0 +1,5 @@
+{
+  "name": "test-package-a",
+  "version": "1.0.0",
+  "main": "index.js"
+}
diff --git a/packages/playground/nested-deps/test-package-b/package.json b/packages/playground/nested-deps/test-package-b/package.json
new file mode 100644
index 00000000000000..342cf2ded23e3b
--- /dev/null
+++ b/packages/playground/nested-deps/test-package-b/package.json
@@ -0,0 +1,5 @@
+{
+  "name": "test-package-b",
+  "version": "1.0.0",
+  "main": "index.js"
+}
diff --git a/packages/playground/nested-deps/vite.config.js b/packages/playground/nested-deps/vite.config.js
new file mode 100644
index 00000000000000..e512df128f26bf
--- /dev/null
+++ b/packages/playground/nested-deps/vite.config.js
@@ -0,0 +1,8 @@
+/**
+ * @type {import('vite').UserConfig}
+ */
+module.exports = {
+  optimizeDeps: {
+    include: ['test-package-a', 'test-package-b']
+  }
+}
diff --git a/packages/playground/optimize-deps/cjs-dynamic.js b/packages/playground/optimize-deps/cjs-dynamic.js
index dceffd811772d7..4d3856d8f69a92 100644
--- a/packages/playground/optimize-deps/cjs-dynamic.js
+++ b/packages/playground/optimize-deps/cjs-dynamic.js
@@ -8,12 +8,12 @@
 
   const clip = await import('clipboard')
   if (typeof clip.default === 'function') {
-    document.querySelector('.cjs-dynamic-clipboard').textContent = 'ok'
+    text('.cjs-dynamic-clipboard', 'ok')
   }
 
   const { Socket } = await import('phoenix')
   if (typeof Socket === 'function') {
-    document.querySelector('.cjs-dynamic-phoenix').textContent = 'ok'
+    text('.cjs-dynamic-phoenix', 'ok')
   }
 
   function App() {
@@ -34,4 +34,8 @@
     React.createElement(App),
     document.querySelector('.cjs-dynamic')
   )
+
+  function text(el, text) {
+    document.querySelector(el).textContent = text
+  }
 })()
diff --git a/packages/playground/optimize-deps/cjs.js b/packages/playground/optimize-deps/cjs.js
index 196d395edc30a2..9dc613c4b3ba71 100644
--- a/packages/playground/optimize-deps/cjs.js
+++ b/packages/playground/optimize-deps/cjs.js
@@ -7,11 +7,11 @@ import { Socket } from 'phoenix'
 import clip from 'clipboard'
 
 if (typeof clip === 'function') {
-  document.querySelector('.cjs-clipboard').textContent = 'ok'
+  text('.cjs-clipboard', 'ok')
 }
 
 if (typeof Socket === 'function') {
-  document.querySelector('.cjs-phoenix').textContent = 'ok'
+  text('.cjs-phoenix', 'ok')
 }
 
 function App() {
@@ -29,3 +29,7 @@ function App() {
 }
 
 ReactDOM.render(React.createElement(App), document.querySelector('.cjs'))
+
+function text(el, text) {
+  document.querySelector(el).textContent = text
+}
diff --git a/packages/playground/optimize-deps/index.html b/packages/playground/optimize-deps/index.html
index 1bf9be5ca2d2e2..7310ab759f4249 100644
--- a/packages/playground/optimize-deps/index.html
+++ b/packages/playground/optimize-deps/index.html
@@ -48,26 +48,28 @@ 

Dep with changes from esbuild plugin

const globbed = import.meta.globEager('./glob/*.js') import { camelCase } from 'dep-linked' - document.querySelector('.deps-linked').textContent = camelCase('foo-bar-baz') + text('.deps-linked', camelCase('foo-bar-baz')) import { msg, VueSFC } from 'dep-linked-include' - document.querySelector('.force-include').textContent = msg - document.querySelector('.plugin').textContent = VueSFC.render() + text('.force-include', msg) + text('.plugin', VueSFC.render()) import * as linked from 'dep-linked-include' const keys = Object.keys(linked) if (keys.length) { - document.querySelector('.import-star').textContent = `[success] ${keys.join( - ', ' - )}` + text('.import-star', `[success] ${keys.join(', ')}`) } import { createApp } from 'vue' import { createStore } from 'vuex' if (typeof createApp === 'function' && typeof createStore === 'function') { - document.querySelector('.vue').textContent = '[success]' + text('.vue', '[success]') } import { hello } from 'dep-esbuild-plugin-transform' - document.querySelector('.esbuild-plugin').textContent = hello() + text('.esbuild-plugin', hello()) + + function text(el, text) { + document.querySelector(el).textContent = text + } diff --git a/packages/playground/ssr-vue/package.json b/packages/playground/ssr-vue/package.json index 77f02fedc6260e..cfdcc051ded2e9 100644 --- a/packages/playground/ssr-vue/package.json +++ b/packages/playground/ssr-vue/package.json @@ -5,8 +5,10 @@ "scripts": { "dev": "node server", "build": "yarn build:client && yarn build:server", + "build:noExternal": "yarn build:client && yarn build:server:noExternal", "build:client": "vite build --ssrManifest --outDir dist/client", "build:server": "vite build --ssr src/entry-server.js --outDir dist/server", + "build:server:noExternal": "vite build --config vite.config.noexternal.js --ssr src/entry-server.js --outDir dist/server", "generate": "vite build --ssrManifest --outDir dist/static && yarn build:server && node prerender", "serve": "cross-env NODE_ENV=production node server", "debug": "node --inspect-brk server" diff --git a/packages/playground/ssr-vue/vite.config.noexternal.js b/packages/playground/ssr-vue/vite.config.noexternal.js new file mode 100644 index 00000000000000..ac74bf1430e94e --- /dev/null +++ b/packages/playground/ssr-vue/vite.config.noexternal.js @@ -0,0 +1,22 @@ +const config = require('./vite.config.js') +/** + * @type {import('vite').UserConfig} + */ +module.exports = Object.assign(config, { + ssr: { + noExternal: /./ + }, + resolve: { + // necessary because vue.ssrUtils is only exported on cjs modules + alias: [ + { + find: '@vue/runtime-dom', + replacement: '@vue/runtime-dom/dist/runtime-dom.cjs.js' + }, + { + find: '@vue/runtime-core', + replacement: '@vue/runtime-core/dist/runtime-core.cjs.js' + } + ] + } +}) diff --git a/packages/playground/vue/AsyncComponent.vue b/packages/playground/vue/AsyncComponent.vue new file mode 100644 index 00000000000000..88997bd5e75452 --- /dev/null +++ b/packages/playground/vue/AsyncComponent.vue @@ -0,0 +1,15 @@ + + + diff --git a/packages/playground/vue/Main.vue b/packages/playground/vue/Main.vue index 305d102db7c530..d1d17489443bf7 100644 --- a/packages/playground/vue/Main.vue +++ b/packages/playground/vue/Main.vue @@ -15,6 +15,9 @@
this should be red
+ + + diff --git a/packages/plugin-legacy/CHANGELOG.md b/packages/plugin-legacy/CHANGELOG.md index f8fd87f34df653..0d11be9f41e712 100644 --- a/packages/plugin-legacy/CHANGELOG.md +++ b/packages/plugin-legacy/CHANGELOG.md @@ -1,3 +1,14 @@ +## [1.4.3](https://github.com/vitejs/vite/compare/plugin-legacy@1.4.2...plugin-legacy@1.4.3) (2021-06-27) + + +### Bug Fixes + +* don't force polyfillDynamicImport if renderLegacyChunks is false ([#3695](https://github.com/vitejs/vite/issues/3695)) ([#3774](https://github.com/vitejs/vite/issues/3774)) ([d2a51ca](https://github.com/vitejs/vite/commit/d2a51ca4eda2ca9f99d9a066836d76d2253cfc24)) +* **deps:** update all non-major dependencies ([#3878](https://github.com/vitejs/vite/issues/3878)) ([a66a805](https://github.com/vitejs/vite/commit/a66a8053e9520d20bcf95fce870570c5195bcc91)) +* **plugin-legacy:** chunk may not exist ([#3886](https://github.com/vitejs/vite/issues/3886)) ([dd5931d](https://github.com/vitejs/vite/commit/dd5931d9c1cf382849047332b2c3409755ceebf5)) + + + ## [1.4.2](https://github.com/vitejs/vite/compare/plugin-legacy@1.4.1...plugin-legacy@1.4.2) (2021-06-22) diff --git a/packages/plugin-legacy/index.js b/packages/plugin-legacy/index.js index 63d18954e48eaa..d2ae6fb8f9d809 100644 --- a/packages/plugin-legacy/index.js +++ b/packages/plugin-legacy/index.js @@ -76,7 +76,9 @@ function viteLegacyPlugin(options = {}) { if (!config.build) { config.build = {} } - config.build.polyfillDynamicImport = true + if (genLegacy) { + config.build.polyfillDynamicImport = true + } } } @@ -303,6 +305,7 @@ function viteLegacyPlugin(options = {}) { }, transformIndexHtml(html, { chunk }) { + if (!chunk) return if (chunk.fileName.includes('-legacy')) { // The legacy bundle is built first, and its index.html isn't actually // emitted. Here we simply record its corresponding legacy chunk. diff --git a/packages/plugin-legacy/package.json b/packages/plugin-legacy/package.json index e02a59fa53b694..342c98e512a449 100644 --- a/packages/plugin-legacy/package.json +++ b/packages/plugin-legacy/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-legacy", - "version": "1.4.2", + "version": "1.4.3", "license": "MIT", "author": "Evan You", "files": [ @@ -26,8 +26,8 @@ }, "homepage": "https://github.com/vitejs/vite/tree/main/packages/plugin-legacy#readme", "dependencies": { - "@babel/standalone": "^7.14.6", - "core-js": "^3.14.0", + "@babel/standalone": "^7.14.7", + "core-js": "^3.15.1", "magic-string": "^0.25.7", "regenerator-runtime": "^0.13.7", "systemjs": "^6.10.1" diff --git a/packages/plugin-react-refresh/CHANGELOG.md b/packages/plugin-react-refresh/CHANGELOG.md index 6236cfe196b090..7cddba10fa143d 100644 --- a/packages/plugin-react-refresh/CHANGELOG.md +++ b/packages/plugin-react-refresh/CHANGELOG.md @@ -1,3 +1,22 @@ +## [1.3.5](https://github.com/vitejs/vite/compare/plugin-react-refresh@1.3.4...plugin-react-refresh@1.3.5) (2021-07-05) + + + +## [1.3.4](https://github.com/vitejs/vite/compare/plugin-react-refresh@1.3.3...plugin-react-refresh@1.3.4) (2021-06-27) + + +### Bug Fixes + +* **ci:** fix ci lint step ([#2988](https://github.com/vitejs/vite/issues/2988)) ([4e8ffd8](https://github.com/vitejs/vite/commit/4e8ffd8865e6303d19b5a5ea4501fc54bff4e180)) +* **deps:** update all non-major dependencies ([#3791](https://github.com/vitejs/vite/issues/3791)) ([74d409e](https://github.com/vitejs/vite/commit/74d409eafca8d74ec4a6ece621ea2895bc1f2a32)) + + +### Features + +* **plugin-react-refresh:** add include / exclude options ([#3916](https://github.com/vitejs/vite/issues/3916)) ([c0a4ea1](https://github.com/vitejs/vite/commit/c0a4ea122794973f2e147f9778e5666f6aaca464)) + + + ## [1.3.3](https://github.com/vitejs/vite/compare/plugin-react-refresh@1.3.2...plugin-react-refresh@1.3.3) (2021-04-24) diff --git a/packages/plugin-react-refresh/README.md b/packages/plugin-react-refresh/README.md index 49f51a5cd77048..498d2d7f3126bc 100644 --- a/packages/plugin-react-refresh/README.md +++ b/packages/plugin-react-refresh/README.md @@ -27,6 +27,25 @@ export default { [Full list of Babel parser plugins](https://babeljs.io/docs/en/babel-parser#ecmascript-proposalshttpsgithubcombabelproposals). +## Specifying files to include or exclude from refreshing + +By default, @vite/plugin-react-refresh will process files ending with `.js`, `.jsx`, `.ts`, and `.tsx`, and excludes all files in `node_modules`. + +In some situations you may not want a file to act as an HMR boundary, instead preferring that the changes propagate higher in the stack before being handled. In these cases, you can provide an `include` and/or `exclude` option, which can be regex or a [picomatch](https://github.com/micromatch/picomatch#globbing-features) pattern, or array of either. Files must match include and not exclude to be processed. Note, when using either `include`, or `exclude`, the defaults will not be merged in, so re-apply them if necessary. + +```js +export default { + plugins: [ + reactRefresh({ + // Exclude storybook stories and node_modules + exclude: [/\.stories\.(t|j)sx?$/, /node_modules/], + // Only .tsx files + include: '**/*.tsx' + }) + ] +} +``` + ### Notes - If using TSX, any TS-supported syntax will already be transpiled away so you won't need to specify them here. diff --git a/packages/plugin-react-refresh/index.d.ts b/packages/plugin-react-refresh/index.d.ts index f5197c9089f7b5..20fd573b44beae 100644 --- a/packages/plugin-react-refresh/index.d.ts +++ b/packages/plugin-react-refresh/index.d.ts @@ -6,7 +6,9 @@ type PluginFactory = (options?: Options) => Plugin declare const createPlugin: PluginFactory & { preambleCode: string } export interface Options { - parserPlugins: ParserOptions['plugins'] + parserPlugins?: ParserOptions['plugins'] + include?: string | RegExp | Array + exclude?: string | RegExp | Array } export default createPlugin diff --git a/packages/plugin-react-refresh/index.js b/packages/plugin-react-refresh/index.js index 0a1a415da17d7f..f72a12fa065a51 100644 --- a/packages/plugin-react-refresh/index.js +++ b/packages/plugin-react-refresh/index.js @@ -1,7 +1,7 @@ // @ts-check const fs = require('fs') const { transformSync, ParserOptions } = require('@babel/core') - +const { createFilter } = require('@rollup/pluginutils') const runtimePublicPath = '/@react-refresh' const runtimeFilePath = require.resolve( 'react-refresh/cjs/react-refresh-runtime.development.js' @@ -37,6 +37,10 @@ window.__vite_plugin_react_preamble_installed__ = true function reactRefreshPlugin(opts) { let shouldSkip = false let base = '/' + const filter = createFilter( + (opts && opts.include) || /\.(t|j)sx?$/, + (opts && opts.exclude) || /node_modules/ + ) return { name: 'react-refresh', @@ -65,7 +69,7 @@ function reactRefreshPlugin(opts) { return } - if (!/\.(t|j)sx?$/.test(id) || id.includes('node_modules')) { + if (!filter(id)) { return } diff --git a/packages/plugin-react-refresh/package.json b/packages/plugin-react-refresh/package.json index 5cf65b440f95ec..aaddc9d60cf0fe 100644 --- a/packages/plugin-react-refresh/package.json +++ b/packages/plugin-react-refresh/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-react-refresh", - "version": "1.3.3", + "version": "1.3.5", "license": "MIT", "author": "Evan You", "files": [ @@ -29,6 +29,7 @@ "@babel/core": "^7.14.6", "@babel/plugin-transform-react-jsx-self": "^7.14.5", "@babel/plugin-transform-react-jsx-source": "^7.14.5", - "react-refresh": "^0.9.0" + "@rollup/pluginutils": "^4.1.0", + "react-refresh": "^0.10.0" } } diff --git a/packages/plugin-vue-jsx/CHANGELOG.md b/packages/plugin-vue-jsx/CHANGELOG.md index 6e2bb21a999b6a..3be1d4f9b4c694 100644 --- a/packages/plugin-vue-jsx/CHANGELOG.md +++ b/packages/plugin-vue-jsx/CHANGELOG.md @@ -1,3 +1,19 @@ +## [1.1.6](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.1.5...plugin-vue-jsx@1.1.6) (2021-06-27) + + +### Bug Fixes + +* **deps:** update all non-major dependencies ([#3791](https://github.com/vitejs/vite/issues/3791)) ([74d409e](https://github.com/vitejs/vite/commit/74d409eafca8d74ec4a6ece621ea2895bc1f2a32)) +* **plugin-vue-jsx:** replace default export with helper during SSR ([#3966](https://github.com/vitejs/vite/issues/3966)) ([bc86464](https://github.com/vitejs/vite/commit/bc86464d3c6591eae96e070a1724a3f21874c8ce)) +* **ssr:** normalize manifest filenames ([#3706](https://github.com/vitejs/vite/issues/3706)) ([aa8ca3f](https://github.com/vitejs/vite/commit/aa8ca3f35218c9fb48f87d3f6f4681d379ee45ca)), closes [#3303](https://github.com/vitejs/vite/issues/3303) + + +### Features + +* **plugin-vue-jsx:** jsx plugin should have extra babel plugins option ([#3923](https://github.com/vitejs/vite/issues/3923)) ([aada0c5](https://github.com/vitejs/vite/commit/aada0c5e71e4826cf049596f3459d48b386ea4da)) + + + ## [1.1.5](https://github.com/vitejs/vite/compare/plugin-vue-jsx@1.1.4...plugin-vue-jsx@1.1.5) (2021-06-01) diff --git a/packages/plugin-vue-jsx/index.d.ts b/packages/plugin-vue-jsx/index.d.ts index 22aad9b5eecb45..2cac80ba56632e 100644 --- a/packages/plugin-vue-jsx/index.d.ts +++ b/packages/plugin-vue-jsx/index.d.ts @@ -8,7 +8,7 @@ declare interface FilterOptions { } declare function createPlugin( - options?: VueJSXPluginOptions & FilterOptions + options?: VueJSXPluginOptions & FilterOptions & { babelPlugins?: any[] } ): Plugin export default createPlugin diff --git a/packages/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index 8e7898a58fdc8a..ea36b0b1d91219 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -2,8 +2,9 @@ const babel = require('@babel/core') const jsx = require('@vue/babel-plugin-jsx') const importMeta = require('@babel/plugin-syntax-import-meta') -const { createFilter } = require('@rollup/pluginutils') +const { createFilter, normalizePath } = require('@rollup/pluginutils') const hash = require('hash-sum') +const path = require('path') const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper' const ssrRegisterHelperCode = @@ -30,15 +31,16 @@ function ssrRegisterHelper(comp, filename) { /** * @typedef { import('@rollup/pluginutils').FilterPattern} FilterPattern - * @typedef { { include?: FilterPattern, exclude?: FilterPattern } } CommonOtions + * @typedef { { include?: FilterPattern, exclude?: FilterPattern, babelPlugins?: any[] } } CommonOptions */ /** * - * @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOtions} options + * @param {import('@vue/babel-plugin-jsx').VueJSXPluginOptions & CommonOptions} options * @returns {import('vite').Plugin} */ function vueJsxPlugin(options = {}) { + let root = '' let needHmr = false let needSourceMap = true @@ -63,6 +65,7 @@ function vueJsxPlugin(options = {}) { configResolved(config) { needHmr = config.command === 'serve' && !config.isProduction needSourceMap = config.command === 'serve' || !!config.build.sourcemap + root = config.root }, resolveId(id) { @@ -78,12 +81,21 @@ function vueJsxPlugin(options = {}) { }, transform(code, id, ssr) { - const { include, exclude, ...babelPluginOptions } = options + const { + include, + exclude, + babelPlugins = [], + ...babelPluginOptions + } = options const filter = createFilter(include || /\.[jt]sx$/, exclude) if (filter(id)) { - const plugins = [importMeta, [jsx, babelPluginOptions]] + const plugins = [ + importMeta, + [jsx, babelPluginOptions], + ...babelPlugins + ] if (id.endsWith('.tsx')) { plugins.push([ require('@babel/plugin-transform-typescript'), @@ -191,16 +203,16 @@ function vueJsxPlugin(options = {}) { } if (hotComponents.length) { + if (hasDefault && (needHmr || ssr)) { + result.code = + result.code.replace( + /export default defineComponent/g, + `const __default__ = defineComponent` + ) + `\nexport default __default__` + } + if (needHmr && !ssr) { let code = result.code - if (hasDefault) { - code = - code.replace( - /export default defineComponent/g, - `const __default__ = defineComponent` - ) + `\nexport default __default__` - } - let callbackCode = `` for (const { local, exported, id } of hotComponents) { code += @@ -217,9 +229,10 @@ function vueJsxPlugin(options = {}) { } if (ssr) { + const normalizedId = normalizePath(path.relative(root, id)) let ssrInjectCode = `\nimport { ssrRegisterHelper } from "${ssrRegisterHelperId}"` + - `\nconst __moduleId = ${JSON.stringify(id)}` + `\nconst __moduleId = ${JSON.stringify(normalizedId)}` for (const { local } of hotComponents) { ssrInjectCode += `\nssrRegisterHelper(${local}, __moduleId)` } diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index 08e76aec1e916e..325ed0664afdbb 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.1.5", + "version": "1.1.6", "license": "MIT", "author": "Evan You", "files": [ diff --git a/packages/plugin-vue/CHANGELOG.md b/packages/plugin-vue/CHANGELOG.md index a40f8a48b324a4..77bb09e89a7aad 100644 --- a/packages/plugin-vue/CHANGELOG.md +++ b/packages/plugin-vue/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.2.4](https://github.com/vitejs/vite/compare/plugin-vue@1.2.3...plugin-vue@1.2.4) (2021-06-27) + + +### Bug Fixes + +* **ssr:** normalize manifest filenames ([#3706](https://github.com/vitejs/vite/issues/3706)) ([aa8ca3f](https://github.com/vitejs/vite/commit/aa8ca3f35218c9fb48f87d3f6f4681d379ee45ca)), closes [#3303](https://github.com/vitejs/vite/issues/3303) + + + ## [1.2.3](https://github.com/vitejs/vite/compare/plugin-vue@1.2.2...plugin-vue@1.2.3) (2021-06-01) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index f4c8d4494ff5a2..76b1beb6f5751f 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@vitejs/plugin-vue", - "version": "1.2.3", + "version": "1.2.4", "license": "MIT", "author": "Evan You", "files": [ diff --git a/packages/plugin-vue/src/main.ts b/packages/plugin-vue/src/main.ts index 98bca03db6f081..b6dfd03714cefd 100644 --- a/packages/plugin-vue/src/main.ts +++ b/packages/plugin-vue/src/main.ts @@ -8,6 +8,7 @@ import { setDescriptor } from './utils/descriptorCache' import { PluginContext, TransformPluginContext } from 'rollup' +import { normalizePath } from '@rollup/pluginutils' import { resolveScript } from './script' import { transformTemplateInMain } from './template' import { isOnlyTemplateChanged, isEqualBlock } from './handleHotUpdate' @@ -143,13 +144,16 @@ export async function transformMain( // SSR module registration by wrapping user setup if (ssr) { + const normalizedFilename = normalizePath( + path.relative(options.root, filename) + ) output.push( `import { useSSRContext as __vite_useSSRContext } from 'vue'`, `const _sfc_setup = _sfc_main.setup`, `_sfc_main.setup = (props, ctx) => {`, ` const ssrContext = __vite_useSSRContext()`, ` ;(ssrContext.modules || (ssrContext.modules = new Set())).add(${JSON.stringify( - filename + normalizedFilename )})`, ` return _sfc_setup ? _sfc_setup(props, ctx) : undefined`, `}` diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index 218c54cb112ce0..ebd2ed8c8fa1ea 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,103 @@ +# [2.4.0](https://github.com/vitejs/vite/compare/v2.4.0-beta.3...v2.4.0) (2021-07-05) + + + +# [2.4.0-beta.3](https://github.com/vitejs/vite/compare/v2.4.0-beta.2...v2.4.0-beta.3) (2021-07-02) + + +### Bug Fixes + +* **ssr:** Transform named default exports without altering scope ([#4053](https://github.com/vitejs/vite/issues/4053)) ([5211aaf](https://github.com/vitejs/vite/commit/5211aaf9b71022a1153dd3ccdef540fd51be72c0)) +* add `type: "module"` hint to cache directory ([#4063](https://github.com/vitejs/vite/issues/4063)) ([58a29b2](https://github.com/vitejs/vite/commit/58a29b241662f77dbf971967b913f4e75f91fe26)) +* allow preprocessor to be installed outside of the root directory ([#3988](https://github.com/vitejs/vite/issues/3988)) ([a0a80f8](https://github.com/vitejs/vite/commit/a0a80f8e992393f01b4b7377e7dc53059ddf1fe1)) +* Avoid importing in source that __vitePreload has declared (close [#4016](https://github.com/vitejs/vite/issues/4016)) ([#4041](https://github.com/vitejs/vite/issues/4041)) ([bd34203](https://github.com/vitejs/vite/commit/bd34203bc40d6a406dfac3ab6cb41f5dfed63a77)) +* ensure that esbuild uses the same working directory as Vite ([#4001](https://github.com/vitejs/vite/issues/4001)) ([19abafe](https://github.com/vitejs/vite/commit/19abafeedda8008f4cc9eeda4cf8cb46e57de8b9)) +* fix esbuild break when importRe matches multiline import ([#4054](https://github.com/vitejs/vite/issues/4054)) ([eb2e41b](https://github.com/vitejs/vite/commit/eb2e41b098fb3d5f367c1f4fdfcad12f7538ac16)) +* skip redirect and error fallback on middleware mode ([#4057](https://github.com/vitejs/vite/issues/4057)) ([d156a9f](https://github.com/vitejs/vite/commit/d156a9f364dddcfc41338f83e39db38a00a2ceb0)) +* the current main branch code build the vite project error ([#4059](https://github.com/vitejs/vite/issues/4059)) ([4adc970](https://github.com/vitejs/vite/commit/4adc9706874581d2d5048fb48c135154591360cf)) +* use `.mjs` extension for injected client modules ([#4061](https://github.com/vitejs/vite/issues/4061)) ([cca92c4](https://github.com/vitejs/vite/commit/cca92c47d54e0f96b56964f13fbe0b2d050c5ed9)) +* use path type import, fix [#4028](https://github.com/vitejs/vite/issues/4028) ([#4031](https://github.com/vitejs/vite/issues/4031)) ([e092e89](https://github.com/vitejs/vite/commit/e092e899dad28f50aaa004419e9da50cf31db72d)) + + + +# [2.4.0-beta.2](https://github.com/vitejs/vite/compare/v2.4.0-beta.1...v2.4.0-beta.2) (2021-06-29) + + +### Bug Fixes + +* revert resolve nested dependencies [#3753](https://github.com/vitejs/vite/issues/3753) ([#4019](https://github.com/vitejs/vite/issues/4019)) ([b6f4293](https://github.com/vitejs/vite/commit/b6f4293435bf90c9a64476d8bfbb022f4f2af9a9)), closes [#4005](https://github.com/vitejs/vite/issues/4005) +* **commonjs:** `ignoreDynamicRequires` should default to `false` ([#4015](https://github.com/vitejs/vite/issues/4015)) ([c08069c](https://github.com/vitejs/vite/commit/c08069cb3bdf7e7aa16d9cfaef4c1aea3a29cfa2)), closes [/github.com/vitejs/vite/pull/3353#issuecomment-851520683](https://github.com//github.com/vitejs/vite/pull/3353/issues/issuecomment-851520683) [#3426](https://github.com/vitejs/vite/issues/3426) [#3997](https://github.com/vitejs/vite/issues/3997) +* **css:** skip comma when matching css url ([#4004](https://github.com/vitejs/vite/issues/4004)) ([7d0bc26](https://github.com/vitejs/vite/commit/7d0bc2691f0291c3a9b0df992554f18bf85c8892)) + + + +# [2.4.0-beta.1](https://github.com/vitejs/vite/compare/v2.4.0-beta.0...v2.4.0-beta.1) (2021-06-29) + + +### Bug Fixes + +* **hmr:** entry mod's importers contains css mod invalidate hmr ([#3929](https://github.com/vitejs/vite/issues/3929)) ([d97b33a](https://github.com/vitejs/vite/commit/d97b33a8cb9a72ed64244f239900a9a862b6ba68)) +* **types:** correct import of types ([#4003](https://github.com/vitejs/vite/issues/4003)) ([4954636](https://github.com/vitejs/vite/commit/4954636c859fbfce76d02aea7881e59435fa3211)) + + +### Features + +* allow passing options to rollupjs dynamic import vars plugin ([#3047](https://github.com/vitejs/vite/issues/3047)) ([5507b4c](https://github.com/vitejs/vite/commit/5507b4c912d2e0e36e63488f5db8e9d1bb0a80f6)) + + + +# [2.4.0-beta.0](https://github.com/vitejs/vite/compare/v2.3.8...v2.4.0-beta.0) (2021-06-27) + +### BREAKING CHANGES + +- **server:** `server.fsServe` renamed to `server.fs` ([#3965](https://github.com/vitejs/vite/pull/3965)) +- **server:** `server.fs.root` deprecated in favor of `server.fs.allow` ([#3968](https://github.com/vitejs/vite/pull/3968)) + +### Security + +We have improved the file serving boundaries detection with ([#3784](https://github.com/vitejs/vite/issues/3784)). While it's still experimental and **disabled by default**, you can opt-in it by + +```js +// vite.config.js +export default { + server: { + fs: { + strict: true + } + } +} +``` + +It should smartly serve the files related to your project (directly imported, linked deps, etc.) while denying the rest. If you find any false-negative, please [open an issue](https://github.com/vitejs/vite/issues/new?assignees=&labels=pending+triage&template=bug_report.yml) with reproduction to report. + +### Bug Fixes + +* **build:** bundle non-inlined workers with rollup ([#2494](https://github.com/vitejs/vite/issues/2494)) ([18a2208](https://github.com/vitejs/vite/commit/18a22089df34c32daddf3b280c58f25cae73f722)) +* resolve nested dependencies ([#3254](https://github.com/vitejs/vite/issues/3254)) ([#3753](https://github.com/vitejs/vite/issues/3753)) ([8467f64](https://github.com/vitejs/vite/commit/8467f64aee218dcb3135bb832ccaed36d647052f)) +* **css:** file or contents missing error in build watch ([#3742](https://github.com/vitejs/vite/issues/3742)) ([#3747](https://github.com/vitejs/vite/issues/3747)) ([26b1b99](https://github.com/vitejs/vite/commit/26b1b9988db1ab980ca816d1914b26d6d3424502)) +* **deps:** update all non-major dependencies ([#3878](https://github.com/vitejs/vite/issues/3878)) ([a66a805](https://github.com/vitejs/vite/commit/a66a8053e9520d20bcf95fce870570c5195bcc91)) +* **scan:** 'for await' support in script setup for dev server ([#3889](https://github.com/vitejs/vite/issues/3889)) ([dd46cd1](https://github.com/vitejs/vite/commit/dd46cd1d030dcfffcbb2f20aff2b388cd18700f4)) +* **scan:** avoid breaking html comment regex inside script of scanned html-like files ([bb095db](https://github.com/vitejs/vite/commit/bb095db11db5c7a12db6dcee866694f1f68d1e15)) +* **ssr:** fix binding overwrite at nested function, fix [#3856](https://github.com/vitejs/vite/issues/3856) ([#3869](https://github.com/vitejs/vite/issues/3869)) ([85f51c1](https://github.com/vitejs/vite/commit/85f51c191d4d3317c5796e6c614ade6f7c21dddf)) +* **ssr:** normalize manifest filenames ([#3706](https://github.com/vitejs/vite/issues/3706)) ([aa8ca3f](https://github.com/vitejs/vite/commit/aa8ca3f35218c9fb48f87d3f6f4681d379ee45ca)), closes [#3303](https://github.com/vitejs/vite/issues/3303) +* **ssr:** not flatten export * as (fix [#3934](https://github.com/vitejs/vite/issues/3934)) ([#3954](https://github.com/vitejs/vite/issues/3954)) ([7381d27](https://github.com/vitejs/vite/commit/7381d27564045a05cffbe4229d71d64b5a791042)) +* **ssr:** not importing browser exports, fix [#3772](https://github.com/vitejs/vite/issues/3772) ([#3933](https://github.com/vitejs/vite/issues/3933)) ([f623ba3](https://github.com/vitejs/vite/commit/f623ba37dbc517656a7ffb10bc1b3cb221a4bc72)) +* do not end server process in CI ([#3659](https://github.com/vitejs/vite/issues/3659)) ([5999444](https://github.com/vitejs/vite/commit/5999444496b6309460687b0769afad018aa21859)) +* missing styles with build watch ([#3742](https://github.com/vitejs/vite/issues/3742)) ([#3887](https://github.com/vitejs/vite/issues/3887)) ([c9a6efe](https://github.com/vitejs/vite/commit/c9a6efe17108a899e1d1f4cb490973486223da99)) +* multiple css url separation (fix [#3922](https://github.com/vitejs/vite/issues/3922)) ([#3926](https://github.com/vitejs/vite/issues/3926)) ([2d01e62](https://github.com/vitejs/vite/commit/2d01e62a70e534694ee1d87f4a328e796ae4c8fe)) +* only downgrade target to es2019 when actually using terser ([bd8723e](https://github.com/vitejs/vite/commit/bd8723eb36be368b4a45240e1f0159fbd40a81a4)) + + +### Features + +* add client events to import.meta.hot.on ([#3638](https://github.com/vitejs/vite/issues/3638)) ([de1ddd4](https://github.com/vitejs/vite/commit/de1ddd401802784a74f5106c5173945e760d3f03)) +* fs-serve import graph awareness ([#3784](https://github.com/vitejs/vite/issues/3784)) ([c45a02f](https://github.com/vitejs/vite/commit/c45a02f0279103be922a2d24b8cd05141e0ff165)) +* generate inline sourcemaps for bundled vite.config.js files ([#3949](https://github.com/vitejs/vite/issues/3949)) ([cff2fcd](https://github.com/vitejs/vite/commit/cff2fcd8db98bb1c046816fd2e01dcbffbe86629)) +* support for regex for ssr.noExternal ([#3819](https://github.com/vitejs/vite/issues/3819)) ([330c94c](https://github.com/vitejs/vite/commit/330c94c4355e4f091e6e4f46c6a47dbfba410e40)) +* support new URL(url, import.meta.url) usage ([4cbb40d](https://github.com/vitejs/vite/commit/4cbb40d2f1a4050c9944e7e1d9e0f5b204b7e37b)) + + + ## [2.3.8](https://github.com/vitejs/vite/compare/v2.3.7...v2.3.8) (2021-06-19) @@ -12,7 +112,7 @@ * **hmr/css:** fix infinite recursion on hmr ([#3865](https://github.com/vitejs/vite/issues/3865)) ([0d5726f](https://github.com/vitejs/vite/commit/0d5726fff2fe724ffec3c0621e3dcd6775b0fe8b)) * ?import with trailing = added by some servers ([#3805](https://github.com/vitejs/vite/issues/3805)) ([460d1cd](https://github.com/vitejs/vite/commit/460d1cda317e4c4d03434f2b3d8de9152620005b)) * don't replace `process.env` if `process` not global variable ([#3703](https://github.com/vitejs/vite/issues/3703)) ([5aeadb7](https://github.com/vitejs/vite/commit/5aeadb719944152be7ed9f9472aa2238ea3557c0)) -* upgrade esbuild for esm compatibility ([#3718](https://github.com/vitejs/vite/issues/3718)) ([dbb5eab](https://github.com/vitejs/vite/commit/dbb5eabe246747abab187a6c8d90cd418856e048)), closes [/github.com/evanw/esbuild/blob/master/CHANGELOG.md#0127](https://github.com//github.com/evanw/esbuild/blob/master/CHANGELOG.md/issues/0127) [#3399](https://github.com/vitejs/vite/issues/3399) [#3413](https://github.com/vitejs/vite/issues/3413) +* upgrade esbuild for esm compatibility ([#3718](https://github.com/vitejs/vite/issues/3718)) ([dbb5eab](https://github.com/vitejs/vite/commit/dbb5eabe246747abab187a6c8d90cd418856e048)), closes [#3399](https://github.com/vitejs/vite/issues/3399) [#3413](https://github.com/vitejs/vite/issues/3413) ### Features diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index 1e40a4063fa73d..920aa5e15d2d67 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -25,7 +25,7 @@ SOFTWARE. # Licenses of bundled dependencies The published Vite artifact additionally contains code with the following licenses: -Apache-2.0, MIT, ISC, BSD-2-Clause, (MIT), (BSD-3-Clause OR GPL-2.0), BSD-3-Clause, CC0-1.0 +Apache-2.0, MIT, ISC, BSD-3-Clause, BSD-2-Clause, (MIT), (BSD-3-Clause OR GPL-2.0), CC0-1.0 # Bundled dependencies: ## @ampproject/remapping @@ -35,26 +35,6 @@ Repository: git+https://github.com/ampproject/remapping.git --------------------------------------- -## @babel/code-frame -License: MIT -By: Sebastian McKenzie -Repository: https://github.com/babel/babel.git - ---------------------------------------- - -## @babel/helper-validator-identifier -License: MIT -Repository: https://github.com/babel/babel.git - ---------------------------------------- - -## @babel/highlight -License: MIT -By: suchipi -Repository: https://github.com/babel/babel.git - ---------------------------------------- - ## @nodelib/fs.scandir License: MIT Repository: https://github.com/nodelib/nodelib/tree/master/packages/fs/fs.scandir @@ -130,6 +110,30 @@ Repository: rollup/plugins --------------------------------------- +## @tsconfig/node10 +License: MIT +Repository: https://github.com/tsconfig/bases.git + +--------------------------------------- + +## @tsconfig/node12 +License: MIT +Repository: https://github.com/tsconfig/bases.git + +--------------------------------------- + +## @tsconfig/node14 +License: MIT +Repository: https://github.com/tsconfig/bases.git + +--------------------------------------- + +## @tsconfig/node16 +License: MIT +Repository: https://github.com/tsconfig/bases.git + +--------------------------------------- + ## @vue/compiler-core License: MIT By: Evan You @@ -214,6 +218,13 @@ Repository: https://github.com/micromatch/anymatch --------------------------------------- +## arg +License: MIT +By: Josh Junon +Repository: zeit/arg + +--------------------------------------- + ## array-union License: MIT By: Sindre Sorhus @@ -263,6 +274,12 @@ Repository: erwinmombay/brotli-size --------------------------------------- +## buffer-from +License: MIT +Repository: LinusU/buffer-from + +--------------------------------------- + ## builtin-modules License: MIT By: Sindre Sorhus @@ -284,13 +301,6 @@ Repository: egoist/cac --------------------------------------- -## callsites -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/callsites - ---------------------------------------- - ## chalk License: MIT Repository: chalk/chalk @@ -381,10 +391,10 @@ Repository: expressjs/cors --------------------------------------- -## cosmiconfig +## create-require License: MIT -By: David Clark, Bogdan Chadkin, Suhas Karanth -Repository: git+https://github.com/davidtheclark/cosmiconfig.git +By: Maël Nison, Paul Soporan, Pooya Parsa +Repository: nuxt-contrib/create-require --------------------------------------- @@ -428,6 +438,12 @@ Repository: git://github.com/visionmedia/debug.git --------------------------------------- +## diff +License: BSD-3-Clause +Repository: git://github.com/kpdecker/jsdiff.git + +--------------------------------------- + ## dir-glob License: MIT By: Kevin Mårtensson @@ -475,12 +491,6 @@ Repository: pillarjs/encodeurl --------------------------------------- -## error-ex -License: MIT -Repository: qix-/node-error-ex - ---------------------------------------- - ## es-module-lexer License: MIT By: Guy Bedford @@ -655,13 +665,6 @@ Repository: sindresorhus/import-cwd --------------------------------------- -## import-fresh -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/import-fresh - ---------------------------------------- - ## import-from License: MIT By: Sindre Sorhus @@ -669,13 +672,6 @@ Repository: sindresorhus/import-from --------------------------------------- -## indexes-of -License: MIT -By: Dominic Tarr -Repository: git://github.com/dominictarr/indexes-of.git - ---------------------------------------- - ## inflight License: ISC By: Isaac Z. Schlueter @@ -689,13 +685,6 @@ Repository: git://github.com/isaacs/inherits --------------------------------------- -## is-arrayish -License: MIT -By: Qix -Repository: https://github.com/qix-/node-is-arrayish.git - ---------------------------------------- - ## is-binary-path License: MIT By: Sindre Sorhus @@ -759,20 +748,6 @@ Repository: git+https://github.com/isaacs/isexe.git --------------------------------------- -## js-tokens -License: MIT -By: Simon Lydell -Repository: lydell/js-tokens - ---------------------------------------- - -## json-parse-even-better-errors -License: MIT -By: Kat Marchán -Repository: https://github.com/npm/json-parse-even-better-errors - ---------------------------------------- - ## json5 License: MIT By: Aseem Kishore, Max Nanasy, Andrew Eisenberg, Jordan Tucker @@ -794,10 +769,10 @@ Repository: git+https://github.com/yyx990803/launch-editor.git --------------------------------------- -## lines-and-columns +## lilconfig License: MIT -By: Brian Donovan -Repository: https://github.com/eventualbuddha/lines-and-columns.git +By: antonk52 +Repository: https://github.com/antonk52/lilconfig --------------------------------------- @@ -822,6 +797,13 @@ Repository: https://github.com/rich-harris/magic-string --------------------------------------- +## make-error +License: ISC +By: Julien Fontanet +Repository: git://github.com/JsCommunity/make-error.git + +--------------------------------------- + ## merge-stream License: MIT By: Stephen Sugden @@ -1004,20 +986,6 @@ Repository: sindresorhus/open --------------------------------------- -## parent-module -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/parent-module - ---------------------------------------- - -## parse-json -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/parse-json - ---------------------------------------- - ## parseurl License: MIT By: Douglas Christopher Wilson, Jonathan Ong @@ -1085,27 +1053,6 @@ License: MIT By: Alexander Madyankin Repository: https://github.com/css-modules/postcss-modules.git -> The MIT License (MIT) -> -> Copyright 2015-2016 Alexander Madyankin -> -> 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. - --------------------------------------- ## postcss-modules-extract-imports @@ -1269,6 +1216,12 @@ Repository: http://github.com/mozilla/source-map.git --------------------------------------- +## source-map-support +License: MIT +Repository: https://github.com/evanw/node-source-map-support + +--------------------------------------- + ## sourcemap-codec License: MIT By: Rich Harris @@ -1325,10 +1278,10 @@ Repository: lukeed/totalist --------------------------------------- -## uniq +## ts-node License: MIT -By: Mikola Lysenko -Repository: git://github.com/mikolalysenko/uniq.git +By: Blake Embrey, Andrew Bradley +Repository: git://github.com/TypeStrong/ts-node.git --------------------------------------- @@ -1379,31 +1332,16 @@ License: MIT By: Einar Otto Stangvik Repository: websockets/ws -> The MIT License (MIT) -> -> Copyright (c) 2011 Einar Otto Stangvik -> -> 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. - --------------------------------------- ## yaml License: ISC By: Eemeli Aro Repository: github:eemeli/yaml + +--------------------------------------- + +## yn +License: MIT +By: Sindre Sorhus +Repository: sindresorhus/yn diff --git a/packages/vite/client.d.ts b/packages/vite/client.d.ts index e41118c4dbc2c2..72b29d0d44911c 100644 --- a/packages/vite/client.d.ts +++ b/packages/vite/client.d.ts @@ -1,51 +1,5 @@ /// - -interface ImportMeta { - url: string - - readonly hot?: { - readonly data: any - - 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 - - /** - * @deprecated - */ - acceptDeps(): never - - dispose(cb: (data: any) => void): void - decline(): void - invalidate(): void - - on(event: string, cb: (...args: any[]) => void): void - } - - readonly env: ImportMetaEnv - - glob(pattern: string): Record< - string, - () => Promise<{ - [key: string]: any - }> - > - - globEager(pattern: string): Record< - string, - { - [key: string]: any - } - > -} -interface ImportMetaEnv { - [key: string]: string | boolean | undefined - BASE_URL: string - MODE: string - DEV: boolean - PROD: boolean -} +/// // CSS modules type CSSModuleClasses = { readonly [key: string]: string } diff --git a/packages/vite/package.json b/packages/vite/package.json index 76c2ff92445098..35174e6bfe0d63 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -1,6 +1,6 @@ { "name": "vite", - "version": "2.3.8", + "version": "2.4.0", "license": "MIT", "author": "Evan You", "description": "Native-ESM powered web dev build tool", @@ -14,6 +14,7 @@ "dist", "client.d.ts", "src", + "types", "!/src/**/__tests__/" ], "engines": { @@ -49,7 +50,7 @@ "//": "READ .github/contributing.md to understand what to put under deps vs. devDeps!", "dependencies": { "esbuild": "^0.12.8", - "postcss": "^8.3.4", + "postcss": "^8.3.5", "resolve": "^1.20.0", "rollup": "^2.38.5" }, @@ -77,9 +78,9 @@ "@types/resolve": "^1.20.0", "@types/sass": "^1.16.0", "@types/stylus": "^0.48.35", - "@types/ws": "^7.4.4", - "@vue/compiler-dom": "^3.1.1", - "acorn": "^8.4.0", + "@types/ws": "^7.4.5", + "@vue/compiler-dom": "^3.1.2", + "acorn": "^8.4.1", "acorn-class-fields": "^1.0.0", "acorn-numeric-separator": "^0.3.6", "acorn-static-class-features": "^1.0.0", @@ -88,20 +89,20 @@ "cac": "^6.7.3", "chalk": "^4.1.1", "chokidar": "^3.5.2", - "clean-css": "^4.2.3", + "clean-css": "^5.1.3", "compression": "^1.7.4", "connect": "^3.7.0", "connect-history-api-fallback": "^1.6.0", - "convert-source-map": "^1.7.0", + "convert-source-map": "^1.8.0", "cors": "^2.8.5", "debug": "^4.3.2", - "dotenv": "^8.6.0", + "dotenv": "^10.0.0", "dotenv-expand": "^5.1.0", "es-module-lexer": "^0.6.0", "estree-walker": "^2.0.2", "etag": "^1.8.1", "execa": "^5.1.1", - "fast-glob": "^3.2.5", + "fast-glob": "^3.2.6", "http-proxy": "^1.18.1", "launch-editor-middleware": "^2.2.1", "magic-string": "^0.25.7", @@ -109,9 +110,8 @@ "minimatch": "^3.0.4", "okie": "^1.0.1", "open": "^7.4.2", - "open-in-editor": "^2.2.0", "periscopic": "^2.0.3", - "postcss-import": "^13.0.0", + "postcss-import": "^14.0.2", "postcss-load-config": "^3.0.0", "postcss-modules": "^4.1.3", "resolve.exports": "^1.0.2", @@ -121,7 +121,7 @@ "source-map": "^0.6.1", "source-map-support": "^0.5.19", "strip-ansi": "^6.0.0", - "terser": "^5.7.0", + "terser": "^5.7.1", "tslib": "^2.3.0", "types": "link:./types", "ws": "^7.5.0" diff --git a/packages/vite/rollup.config.js b/packages/vite/rollup.config.js index 8a06ac8c704bdb..34ea08f1692732 100644 --- a/packages/vite/rollup.config.js +++ b/packages/vite/rollup.config.js @@ -26,7 +26,7 @@ const envConfig = { }) ], output: { - dir: path.resolve(__dirname, 'dist/client'), + file: path.resolve(__dirname, 'dist/client', 'env.mjs'), sourcemap: true } } @@ -48,7 +48,7 @@ const clientConfig = { }) ], output: { - dir: path.resolve(__dirname, 'dist/client'), + file: path.resolve(__dirname, 'dist/client', 'client.mjs'), sourcemap: true } } @@ -140,13 +140,13 @@ const nodeConfig = { src: 'require("sugarss")', replacement: `eval('require')('sugarss')` }, - 'import-fresh/index.js': { - src: `require(filePath)`, - replacement: `eval('require')(filePath)` - }, 'import-from/index.js': { pattern: /require\(resolveFrom/g, replacement: `eval('require')(resolveFrom` + }, + 'lilconfig/dist/index.js': { + pattern: /: require,/g, + replacement: `: eval('require'),` } }), // Optional peer deps of ws. Native deps that are mostly for performance. @@ -273,7 +273,9 @@ function licensePlugin() { ) const licenses = new Set() const dependencyLicenseTexts = dependencies - .sort(({ name: nameA }, { name: nameB }) => (nameA > nameB) ? 1 : ((nameB > nameA) ? -1 : 0)) + .sort(({ name: nameA }, { name: nameB }) => + nameA > nameB ? 1 : nameB > nameA ? -1 : 0 + ) .map( ({ name, diff --git a/packages/vite/src/client/client.ts b/packages/vite/src/client/client.ts index 387767991de84f..d247019f3e1d95 100644 --- a/packages/vite/src/client/client.ts +++ b/packages/vite/src/client/client.ts @@ -1,6 +1,15 @@ -import { ErrorPayload, HMRPayload, Update } from 'types/hmrPayload' +import { + ErrorPayload, + FullReloadPayload, + HMRPayload, + PrunePayload, + Update, + UpdatePayload +} from 'types/hmrPayload' +import { CustomEventName } from 'types/customEvent' import { ErrorOverlay, overlayId } from './overlay' import './env' + // injected by the hmr plugin when served declare const __ROOT__: string declare const __BASE__: string @@ -46,6 +55,7 @@ async function handleMessage(payload: HMRPayload) { setInterval(() => socket.send('ping'), __HMR_TIMEOUT__) break case 'update': + notifyListeners('vite:beforeUpdate', payload) // if this is the first update and there's already an error overlay, it // means the page opened with existing server compile error and the whole // module script failed to load (since one of the nested imports is 500). @@ -84,13 +94,11 @@ async function handleMessage(payload: HMRPayload) { }) break case 'custom': { - const cbs = customListenersMap.get(payload.event) - if (cbs) { - cbs.forEach((cb) => cb(payload.data)) - } + notifyListeners(payload.event as CustomEventName, payload.data) break } case 'full-reload': + notifyListeners('vite:beforeFullReload', payload) if (payload.path && payload.path.endsWith('.html')) { // if html file is edited, only reload the page if the browser is // currently on that page. @@ -108,6 +116,7 @@ async function handleMessage(payload: HMRPayload) { } break case 'prune': + notifyListeners('vite:beforePrune', payload) // After an HMR update, some modules are no longer imported on the page // but they may have left behind side effects that need to be cleaned up // (.e.g style injections) @@ -120,6 +129,7 @@ async function handleMessage(payload: HMRPayload) { }) break case 'error': { + notifyListeners('vite:error', payload) const err = payload.err if (enableOverlay) { createErrorOverlay(err) @@ -137,6 +147,27 @@ async function handleMessage(payload: HMRPayload) { } } +function notifyListeners( + event: 'vite:beforeUpdate', + payload: UpdatePayload +): void +function notifyListeners(event: 'vite:beforePrune', payload: PrunePayload): void +function notifyListeners( + event: 'vite:beforeFullReload', + payload: FullReloadPayload +): void +function notifyListeners(event: 'vite:error', payload: ErrorPayload): void +function notifyListeners( + event: CustomEventName, + data: any +): void +function notifyListeners(event: string, data: any): void { + const cbs = customListenersMap.get(event) + if (cbs) { + cbs.forEach((cb) => cb(data)) + } +} + const enableOverlay = __HMR_ENABLE_OVERLAY__ function createErrorOverlay(err: ErrorPayload['err']) { @@ -333,10 +364,10 @@ const hotModulesMap = new Map() const disposeMap = new Map void | Promise>() const pruneMap = new Map void | Promise>() const dataMap = new Map() -const customListenersMap = new Map void)[]>() +const customListenersMap = new Map void)[]>() const ctxToListenersMap = new Map< string, - Map void)[]> + Map void)[]> >() // Just infer the return type for now @@ -427,7 +458,7 @@ export const createHotContext = (ownerPath: string) => { }, // custom events - on(event: string, cb: () => void) { + on: (event: string, cb: (data: any) => void) => { const addToMap = (map: Map) => { const existing = map.get(event) || [] existing.push(cb) diff --git a/packages/vite/src/node/__tests__/scan.spec.ts b/packages/vite/src/node/__tests__/scan.spec.ts index a1f360c035085b..32ff26118b78da 100644 --- a/packages/vite/src/node/__tests__/scan.spec.ts +++ b/packages/vite/src/node/__tests__/scan.spec.ts @@ -1,4 +1,4 @@ -import { scriptRE, commentRE } from '../optimizer/scan' +import { scriptRE, commentRE, importsRE } from '../optimizer/scan' describe('optimizer-scan:script-test', () => { const scriptContent = `import { defineComponent } from 'vue' @@ -64,4 +64,36 @@ describe('optimizer-scan:script-test', () => { expect(tag1).toEqual('