diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 11a9a532fd5456..301b795e15fb5e 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -66,7 +66,7 @@ body: required: true - label: Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) 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. + - 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/core 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/renovate.json5 b/.github/renovate.json5 index 763dfcfc467d9d..06fe0e7ea2aaff 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -28,6 +28,7 @@ "react-router", // `react-router:v6.0.0+` has breaking changes "react-router-dom", // `react-router-dom:v6.0.0+` has breaking changes "source-map", // `source-map:v0.7.0+` needs more investigation + "dotenv-expand", // `dotenv-expand:6.0.0+` has breaking changes (#6858) // ESM Only => https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-move-my-commonjs-project-to-esm "node-fetch", diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64166e7158caf3..69ba432050fa7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ concurrency: jobs: build: + timeout-minutes: 20 runs-on: ${{ matrix.os }} strategy: matrix: @@ -43,7 +44,7 @@ jobs: version: 6 - name: Set node version to ${{ matrix.node_version }} - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: ${{ matrix.node_version }} cache: "pnpm" @@ -67,6 +68,7 @@ jobs: run: pnpm run test-build -- --runInBand lint: + timeout-minutes: 10 runs-on: ubuntu-latest name: "Lint: node-16, ubuntu-latest" steps: @@ -80,7 +82,7 @@ jobs: version: 6 - name: Set node version to 16 - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: 16 cache: "pnpm" diff --git a/.github/workflows/issue-close-require.yml b/.github/workflows/issue-close-require.yml index 02ac374b06c426..97f9dd3a449c3c 100644 --- a/.github/workflows/issue-close-require.yml +++ b/.github/workflows/issue-close-require.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest steps: - name: need reproduction - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "close-issues" token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/issue-labeled.yml b/.github/workflows/issue-labeled.yml index a63021952fd73d..b6f3919dfa63a2 100644 --- a/.github/workflows/issue-labeled.yml +++ b/.github/workflows/issue-labeled.yml @@ -10,7 +10,7 @@ jobs: steps: - name: contribution welcome if: github.event.label.name == 'contribution welcome' || github.event.label.name == 'help wanted' - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "create-comment, remove-labels" token: ${{ secrets.GITHUB_TOKEN }} @@ -21,7 +21,7 @@ jobs: - name: remove pending if: github.event.label.name == 'enhancement' || github.event.label.name == 'bug' || (contains(github.event.label.name, 'pending triage') == false && startsWith(github.event.label.name, 'bug:') == true) - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "remove-labels" token: ${{ secrets.GITHUB_TOKEN }} @@ -30,7 +30,7 @@ jobs: - name: need reproduction if: github.event.label.name == 'need reproduction' - uses: actions-cool/issues-helper@v2 + uses: actions-cool/issues-helper@v3 with: actions: "create-comment, remove-labels" token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000000..9e22af5aed6ee8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,46 @@ +name: Publish Package + +on: + push: + tags: + - "v*" # Push events to matching v*, i.e. v1.0, v20.15.10 + - "plugin-*" # Push events to matching plugin-*, i.e. plugin-(vue|vue-jsx|react|legacy)@1.0.0 + - "create-vite*" # # Push events to matching create-vite*, i.e. create-vite@1.0.0 + +jobs: + publish: + # prevents this action from running on forks + if: github.repository == 'vitejs/vite' + runs-on: ubuntu-latest + environment: Release + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install pnpm + uses: pnpm/action-setup@v2 + with: + version: 6 + + - name: Set node version to 16.x + uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: https://registry.npmjs.org/ + cache: "pnpm" + + - name: Install deps + run: pnpm install + + - name: Creating .npmrc + run: | + cat << EOF > "$HOME/.npmrc" + //registry.npmjs.org/:_authToken=$NPM_TOKEN + EOF + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + + - name: Publish package + run: pnpm run ci-publish -- ${{ github.ref_name }} + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index 5ed9495899340a..f9d5b8de30bec9 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -1,4 +1,4 @@ -name: release +name: Add GitHub Release Tag on: push: diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000000000..4abbb42e5ef159 --- /dev/null +++ b/.npmrc @@ -0,0 +1,7 @@ +hoist-pattern[]=*eslint* +hoist-pattern[]=*babel* +hoist-pattern[]=*jest* +hoist-pattern[]=@emotion/* +hoist-pattern[]=postcss +hoist-pattern[]=pug +hoist-pattern[]=source-map-support diff --git a/.prettierignore b/.prettierignore index 1692b9d26cfa20..c624a3a21eecfe 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,3 +10,4 @@ pnpm-lock.yaml pnpm-workspace.yaml packages/playground/tsconfig-json-load-error/has-error/tsconfig.json packages/playground/html/invalid.html +packages/playground/worker/classic-worker.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5b8f1fed7192c3..31c1f34f3a4815 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,36 @@ To develop and test the core `vite` package: You can alternatively use [Vite.js Docker Dev](https://github.com/nystudio107/vitejs-docker-dev) for a containerized Docker setup for Vite.js development. +## Debugging + +If you want to use break point and explore code execution you can use the ["Run and debug"](https://code.visualstudio.com/docs/editor/debugging) feature from vscode. + +1. Add a `debugger` statement where you want to stop the code execution. + +2. Click on the "Run and Debug" icon in the activity bar of the editor. + +3. Click on the "Javascript Debug Terminal" button. + +4. It will open a terminal, then go to `packages/playground/xxx` and run `pnpm run dev`. + +5. The execution will stop and you'll use the [Debug toolbar](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) to continue, step over, restart the process... + +### Debugging errors in Jest tests using Playwright (Chromium) + +Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Jest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup: + +1. Add a `debugger` statement to the `scripts/jestPerTestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits. + +1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve -- --runInBand resolve`. + +1. Wait for inspector devtools to open in your browser and the debugger to attach. + +1. In the sources panel in the right column, click the play button to resume execution and allow the tests to run which will open a Chromium instance. + +1. Focusing the Chomium instance, you can open the browser devtools and inspect the console there to find the underlying problems. + +1. To close everything, just stop the test process back in your terminal. + ## Testing Vite against external packages You may wish to test your locally-modified copy of Vite against another package that is built with Vite. For pnpm, after building Vite, you can use [`pnpm.overrides`](https://pnpm.io/package_json#pnpmoverrides). Please note that `pnpm.overrides` must be specified in the root `package.json` and you must first list the package as a dependency in the root `package.json`: diff --git a/README.md b/README.md index be96a1bcf73ada..546014a12c7116 100644 --- a/README.md +++ b/README.md @@ -33,10 +33,6 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g [Read the Docs to Learn More](https://vitejs.dev). -## Migrating from 1.x - -Check out the [Migration Guide](https://vitejs.dev/guide/migration.html) if you are upgrading from 1.x. - ## Packages | Package | Version (click for changelogs) | @@ -55,3 +51,11 @@ See [Contributing Guide](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.m ## License MIT + +## Sponsors + +

+ + sponsors + +

diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index fc635028f95a73..ee76a29986d3fb 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -7,6 +7,9 @@ module.exports = { title: 'Vite', description: 'Next Generation Frontend Tooling', head: [['link', { rel: 'icon', type: 'image/svg+xml', href: '/logo.svg' }]], + vue: { + reactivityTransform: true + }, themeConfig: { repo: 'vitejs/vite', logo: '/logo.svg', diff --git a/docs/.vitepress/theme/SponsorsGroup.vue b/docs/.vitepress/theme/SponsorsGroup.vue new file mode 100644 index 00000000000000..691f5f5b0f1dc2 --- /dev/null +++ b/docs/.vitepress/theme/SponsorsGroup.vue @@ -0,0 +1,137 @@ + + + + + + + diff --git a/docs/.vitepress/theme/SponsorsSidebar.vue b/docs/.vitepress/theme/SponsorsSidebar.vue new file mode 100644 index 00000000000000..bb27c8b5ee157d --- /dev/null +++ b/docs/.vitepress/theme/SponsorsSidebar.vue @@ -0,0 +1,31 @@ + + + + + diff --git a/docs/.vitepress/theme/index.js b/docs/.vitepress/theme/index.js index 5d0a1b7a652039..babdc165f30ed8 100644 --- a/docs/.vitepress/theme/index.js +++ b/docs/.vitepress/theme/index.js @@ -1,7 +1,6 @@ import Theme from 'vitepress/theme' import { h } from 'vue' -import sponsors from './sponsors.json' -import './sponsors.css' +import SponsorsSidebar from './SponsorsSidebar.vue' import './custom.css' export default { @@ -9,29 +8,7 @@ export default { Layout() { return h(Theme.Layout, null, { 'sidebar-bottom': () => - h('div', { class: 'sponsors sidebar' }, [ - h( - 'a', - { - href: 'https://github.com/sponsors/yyx990803', - target: '_blank', - rel: 'noopener' - }, - [h('span', 'Sponsors')] - ), - ...sponsors.map(({ href, src, name, id }) => - h( - 'a', - { - href, - target: '_blank', - rel: 'noopener', - 'aria-label': 'sponsor-img' - }, - [h('img', { src, alt: name, id: `sponsor-${id}` })] - ) - ) - ]) + h('div', { class: 'sponsors sidebar' }, [h(SponsorsSidebar)]) }) } } diff --git a/docs/.vitepress/theme/sponsors.css b/docs/.vitepress/theme/sponsors.css deleted file mode 100644 index 904b4945ed57d6..00000000000000 --- a/docs/.vitepress/theme/sponsors.css +++ /dev/null @@ -1,56 +0,0 @@ -.sponsors { - padding: 0 1.5rem 2rem; - font-size: 0.8rem; -} - -.sponsors a { - color: #999; - margin: 1em 2em; - display: block; -} - -.sponsors img { - max-width: 160px; - max-height: 40px; -} - -.sponsors.frontpage { - text-align: center; -} - -.sponsors.frontpage img { - display: inline-block; - vertical-align: middle; -} - -.sponsors.frontpage h2 { - color: #999; - font-size: 1.2rem; - border: none; -} - -.sponsors.sidebar a img { - max-height: 36px; -} - -.platinum-sponsors { - margin-bottom: 1.5em; -} - -.platinum-sponsors a img { - max-width: 240px; - max-height: 60px; -} - -.gold-sponsors { - display: flex; - flex-wrap: wrap; - justify-content: center; - align-items: center; -} - -/* special cases */ -#sponsor-mux { - padding: 5px 0; - min-height: 36px; -} diff --git a/docs/.vitepress/theme/sponsors.json b/docs/.vitepress/theme/sponsors.json deleted file mode 100644 index c8f199969646b2..00000000000000 --- a/docs/.vitepress/theme/sponsors.json +++ /dev/null @@ -1,51 +0,0 @@ -[ - { - "id": "stackblitz", - "name": "StackBlitz", - "href": "https://stackblitz.com/", - "src": "/stackblitz.svg", - "tier": "platinum" - }, - { - "id": "cypress", - "name": "Cypress.io", - "href": "https://cypress.io", - "src": "/cypress.svg" - }, - { - "id": "tailwind", - "name": "Tailwind Labs", - "href": "https://tailwindcss.com", - "src": "/tailwind-labs.svg" - }, - { - "id": "vuejobs", - "name": "Vue Jobs", - "href": "https://vuejobs.com/?ref=vuejs", - "src": "/vuejobs.png" - }, - { - "id": "mux", - "name": "Mux", - "href": "https://mux.com", - "src": "/mux.svg" - }, - { - "id": "plaid", - "name": "Plaid Inc.", - "href": "https://plaid.co.jp/", - "src": "/plaid.svg" - }, - { - "id": "divriots", - "name": "divriots", - "href": "https://divriots.com/", - "src": "/divriots.png" - }, - { - "id": "finclip", - "name": "FinClip", - "href": "https://finclip.com/?from=vite", - "src": "/finclip.png" - } -] diff --git a/docs/config/index.md b/docs/config/index.md index 233e08b8f864e3..27234b01a9b4af 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -508,12 +508,14 @@ export default defineConfig(async ({ command, mode }) => { ### server.hmr -- **Type:** `boolean | { protocol?: string, host?: string, port?: number, path?: string, timeout?: number, overlay?: boolean, clientPort?: number, server?: Server }` +- **Type:** `boolean | { protocol?: string, host?: string, port?: number | false, path?: string, timeout?: number, overlay?: boolean, clientPort?: number, server?: Server }` Disable or configure HMR connection (in cases where the HMR websocket must use a different address from the http server). Set `server.hmr.overlay` to `false` to disable the server error overlay. + Set `server.hmr.port` to `false` when connecting to a domain without a port. + `clientPort` is an advanced option that overrides the port only on the client side, allowing you to serve the websocket on a different port than the client code looks for it on. Useful if you're using an SSL proxy in front of your dev server. When using `server.middlewareMode` or `server.https`, assigning `server.hmr.server` to your HTTP(S) server will process HMR connection requests through your server. This can be helpful when using self-signed certificates or when you want to expose Vite over a network on a single port. @@ -772,19 +774,19 @@ export default defineConfig({ ### build.manifest -- **Type:** `boolean` +- **Type:** `boolean | string` - **Default:** `false` - **Related:** [Backend Integration](/guide/backend-integration) - 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. + 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. When the value is a string, it will be used as the manifest file name. ### build.ssrManifest -- **Type:** `boolean` +- **Type:** `boolean | string` - **Default:** `false` - **Related:** [Server-Side Rendering](/guide/ssr) - When set to `true`, the build will also generate a SSR manifest for determining style links and asset preload directives in production. + When set to `true`, the build will also generate a SSR manifest for determining style links and asset preload directives in production. When the value is a string, it will be used as the manifest file name. ### build.ssr @@ -923,7 +925,7 @@ export default defineConfig({ - **Type:** `string | string[]` - By default, Vite will crawl your index.html to detect dependencies that need to be pre-bundled. If build.rollupOptions.input is specified, Vite will crawl those entry points instead. + By default, Vite will crawl your `index.html` to detect dependencies that need to be pre-bundled. If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead. If neither of these fit your needs, you can specify custom entries using this option - the value should be a [fast-glob pattern](https://github.com/mrmlnc/fast-glob#basic-syntax) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. diff --git a/docs/guide/api-javascript.md b/docs/guide/api-javascript.md index 1651923c06cdcb..ddaa04279737f5 100644 --- a/docs/guide/api-javascript.md +++ b/docs/guide/api-javascript.md @@ -94,7 +94,7 @@ interface ViteDevServer { */ ssrLoadModule( url: string, - options?: { isolated?: boolean } + options?: { fixStacktrace?: boolean } ): Promise> /** * Fix ssr error stacktrace. diff --git a/docs/guide/api-plugin.md b/docs/guide/api-plugin.md index cba57ca6653309..01b42980197473 100644 --- a/docs/guide/api-plugin.md +++ b/docs/guide/api-plugin.md @@ -36,9 +36,7 @@ If your plugin is only going to work for a particular framework, its name should - `vite-plugin-react-` prefix for React Plugins - `vite-plugin-svelte-` prefix for Svelte Plugins -Vite convention for virtual modules is to prefix the user-facing path with `virtual:`. If possible the plugin name should be used as a namespace to avoid collisions with other plugins in the ecosystem. For example, a `vite-plugin-posts` could ask users to import a `virtual:posts` or `virtual:posts/helpers` virtual modules to get build time information. Internally, plugins that use virtual modules should prefix the module ID with `\0` while resolving the id, a convention from the rollup ecosystem. This prevents other plugins from trying to process the id (like node resolution), and core features like sourcemaps can use this info to differentiate between virtual modules and regular files. `\0` is not a permitted char in import URLs so we have to replace them during import analysis. A `\0{id}` virtual id ends up encoded as `/@id/__x00__{id}` during dev in the browser. The id will be decoded back before entering the plugins pipeline, so this is not seen by plugins hooks code. - -Note that modules directly derived from a real file, as in the case of a script module in a Single File Component (like a .vue or .svelte SFC) don't need to follow this convention. SFCs generally generate a set of submodules when processed but the code in these can be mapped back to the filesystem. Using `\0` for these submodules would prevent sourcemaps from working correctly. +See also [Virtual Modules Convention](#virtual-modules-convention). ## Plugins config @@ -84,8 +82,35 @@ export default defineConfig({ It is common convention to author a Vite/Rollup plugin as a factory function that returns the actual plugin object. The function can accept options which allows users to customize the behavior of the plugin. ::: +### Transforming Custom File Types + +```js +const fileRegex = /\.(my-file-ext)$/ + +export default function myPlugin() { + return { + name: 'transform-file', + + transform(src, id) { + if (fileRegex.test(id)) { + return { + code: compileFileToJS(src), + map: null // provide source map if available + } + } + } + } +} +``` + ### Importing a Virtual File +See the example in the [next section](#virtual-modules-convention). + +## Virtual Modules Convention + +Virtual modules are a useful scheme that allows you to pass build time information to the source files using normal ESM import syntax. + ```js export default function myPlugin() { const virtualModuleId = '@my-virtual-module' @@ -115,26 +140,9 @@ import { msg } from '@my-virtual-module' console.log(msg) ``` -### Transforming Custom File Types - -```js -const fileRegex = /\.(my-file-ext)$/ - -export default function myPlugin() { - return { - name: 'transform-file', +Virtual modules in Vite (and Rollup) are prefixed with `virtual:` for the user-facing path by convention. If possible the plugin name should be used as a namespace to avoid collisions with other plugins in the ecosystem. For example, a `vite-plugin-posts` could ask users to import a `virtual:posts` or `virtual:posts/helpers` virtual modules to get build time information. Internally, plugins that use virtual modules should prefix the module ID with `\0` while resolving the id, a convention from the rollup ecosystem. This prevents other plugins from trying to process the id (like node resolution), and core features like sourcemaps can use this info to differentiate between virtual modules and regular files. `\0` is not a permitted char in import URLs so we have to replace them during import analysis. A `\0{id}` virtual id ends up encoded as `/@id/__x00__{id}` during dev in the browser. The id will be decoded back before entering the plugins pipeline, so this is not seen by plugins hooks code. - transform(src, id) { - if (fileRegex.test(id)) { - return { - code: compileFileToJS(src), - map: null // provide source map if available - } - } - } - } -} -``` +Note that modules directly derived from a real file, as in the case of a script module in a Single File Component (like a .vue or .svelte SFC) don't need to follow this convention. SFCs generally generate a set of submodules when processed but the code in these can be mapped back to the filesystem. Using `\0` for these submodules would prevent sourcemaps from working correctly. ## Universal Hooks diff --git a/docs/guide/dep-pre-bundling.md b/docs/guide/dep-pre-bundling.md index 6864ef55899eba..a72e06e6aff944 100644 --- a/docs/guide/dep-pre-bundling.md +++ b/docs/guide/dep-pre-bundling.md @@ -3,10 +3,10 @@ When you run `vite` for the first time, you may notice this message: ``` -Optimizable dependencies detected: -react, react-dom -Pre-bundling them to speed up dev server page load... -(this will be run only when your dependencies have changed) +Pre-bundling dependencies: + react + react-dom +(this will be run only when your dependencies or config have changed) ``` ## The Why @@ -28,6 +28,8 @@ This is Vite performing what we call "dependency pre-bundling". This process ser By pre-bundling `lodash-es` into a single module, we now only need one HTTP request instead! +Note that this only applies in development mode. + ## Automatic Dependency Discovery If an existing cache is not found, Vite will crawl your source code and automatically discover dependency imports (i.e. "bare imports" that expect to be resolved from `node_modules`) and use these found imports as entry points for the pre-bundle. The pre-bundling is performed with `esbuild` so it's typically very fast. @@ -36,11 +38,27 @@ After the server has already started, if a new dependency import is encountered ## Monorepos and Linked Dependencies -In a monorepo setup, a dependency may be a linked package from the same repo. Vite automatically detects dependencies that are not resolved from `node_modules` and treats the linked dep as source code. It will not attempt to bundle the linked dep, and instead will analyze the linked dep's dependency list instead. +In a monorepo setup, a dependency may be a linked package from the same repo. Vite automatically detects dependencies that are not resolved from `node_modules` and treats the linked dep as source code. It will not attempt to bundle the linked dep, and will analyze the linked dep's dependency list instead. + +However, this requires the linked dep to be exported as ESM. If not, you can add the dependency to [`optimizeDeps.include`](/config/#optimizedeps-include) and [`build.commonjsOptions.include`](/config/#build-commonjsoptions) in your config. + +```js +export default defineConfig({ + optimizeDeps: { + include: ['linked-dep'] + }, + build: { + commonjsOptions: { + include: [/linked-dep/, /node_modules/] + } + } +}) +``` + +When making changes to the linked dep, restart the dev server with the `--force` command line option for the changes to take effect. -::: warning Note -Linked dependencies might not work properly in the final build due to differences in dependency resolution. -Use `npm package` instead for all local dependencies to avoid issues in the final bundle. +::: warning Deduping +Due to differences in linked dependency resolution, transitive dependencies can deduplicated incorrectly, causing issues when used in runtime. If you stumble on this issue, use `npm pack` on the linked dependency to fix it. ::: ## Customizing the Behavior @@ -57,7 +75,7 @@ Both `include` and `exclude` can be used to deal with this. If the dependency is Vite caches the pre-bundled dependencies in `node_modules/.vite`. It determines whether it needs to re-run the pre-bundling step based on a few sources: -- The `dependencies` list in your `package.json` +- The `dependencies` list in your `package.json`. - Package manager lockfiles, e.g. `package-lock.json`, `yarn.lock`, or `pnpm-lock.yaml`. - Relevant fields in your `vite.config.js`, if present. diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index 1852164c4ae523..d3a6a575bce64c 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -110,4 +110,4 @@ NODE_ENV=production VITE_APP_TITLE=My App (staging) ``` -Now your staging app should have production-like behavior, but displaying a different title from production. +Now your staging app should have production-like behavior, but display a different title from production. diff --git a/docs/guide/features.md b/docs/guide/features.md index da8e3b1de092b2..c7fd2424b53cb1 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -298,6 +298,22 @@ const modules = { } ``` +`import.meta.glob` and `import.meta.globEager` also support importing files as strings, similar to [Importing Asset as String](https://vitejs.dev/guide/assets.html#importing-asset-as-string). Here, we use the [Import Assertions](https://github.com/tc39/proposal-import-assertions#synopsis) syntax to import. + +```js +const modules = import.meta.glob('./dir/*.js', { assert: { type: 'raw' } }) +``` + +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' +} +``` + Note that: - This is a Vite-only feature and is not a web or ES standard. diff --git a/docs/guide/static-deploy.md b/docs/guide/static-deploy.md index 95f7b0ae5ed174..43b047dd7f53eb 100644 --- a/docs/guide/static-deploy.md +++ b/docs/guide/static-deploy.md @@ -40,7 +40,7 @@ $ npm run build $ npm run preview ``` -The `vite preview` command will boot up local static web server that serves the files from `dist` at http://localhost:5000. It's an easy way to check if the production build looks OK in your local environment. +The `vite preview` command will boot up local static web server that serves the files from `dist` at `http://localhost:4173`. It's an easy way to check if the production build looks OK in your local environment. You may configure the port of the server py passing `--port` flag as an argument. @@ -52,7 +52,7 @@ You may configure the port of the server py passing `--port` flag as an argument } ``` -Now the `preview` method will launch the server at http://localhost:8080. +Now the `preview` method will launch the server at `http://localhost:8080`. ## GitHub Pages @@ -80,6 +80,7 @@ Now the `preview` method will launch the server at http://localhost:8080. # echo 'www.example.com' > CNAME git init + git checkout -b main git add -A git commit -m 'deploy' @@ -164,12 +165,27 @@ You can also run the above script in your CI setup to enable automatic deploymen ## Netlify -1. On [Netlify](https://netlify.com), setup up a new project from GitHub with the following settings: +1. Install the [Netlify CLI](https://cli.netlify.com/). +2. Create a new site using `ntl init`. +3. Deploy using `ntl deploy`. - - **Build Command:** `vite build` or `npm run build` - - **Publish directory:** `dist` +```bash +# Install the Netlify CLI +$ npm install -g netlify-cli + +# Create a new site in Netlify +$ ntl init + +# Deploy to a unique preview URL +$ ntl deploy +``` -2. Hit the deploy button. +The Netlify CLI will share with you a preview URL to inspect. When you are ready to go into production, use the `prod` flag: + +```bash +# Deploy the site into production +$ ntl deploy --prod +``` ## Google Firebase @@ -267,15 +283,30 @@ You can also deploy to a [custom domain](http://surge.sh/help/adding-a-custom-do ## Vercel -To deploy your Vite app with a [Vercel for Git](https://vercel.com/docs/git), make sure it has been pushed to a Git repository. +### Vercel CLI + +1. Install the [Vercel CLI](https://vercel.com/cli) and run `vercel` to deploy. +2. Vercel will detect that you are using Vite and will enable the correct settings for your deployment. +3. Your application is deployed! (e.g. [vite-vue-template.vercel.app](https://vite-vue-template.vercel.app/)) + +```bash +$ npm i -g vercel +$ vercel init vite +Vercel CLI +> Success! Initialized "vite" example in ~/your-folder. +- To deploy, `cd vite` and run `vercel`. +``` -Go to https://vercel.com/import/git and import the project into Vercel using your Git of choice (GitHub, GitLab or BitBucket). Follow the wizard to select the project root with the project's `package.json` and override the build step using `npm run build` and the output dir to be `./dist` +### Vercel for Git -![Override Vercel Configuration](../images/vercel-configuration.png) +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/)) -After your project has been imported, all subsequent pushes to branches will generate Preview Deployments, and all changes made to the Production Branch (commonly "main") will result in a Production Deployment. +After your project has been imported and deployed, all subsequent pushes to branches will generate [Preview Deployments](https://vercel.com/docs/concepts/deployments/environments#preview), and all changes made to the Production Branch (commonly “main”) will result in a [Production Deployment](https://vercel.com/docs/concepts/deployments/environments#production). -Once deployed, you will get a URL to see your app live, such as the following: https://vite.vercel.app +Learn more about Vercel’s [Git Integration](https://vercel.com/docs/concepts/git). ## Azure Static Web Apps diff --git a/docs/guide/why.md b/docs/guide/why.md index 59e9c138eb7dca..89ca7698394246 100644 --- a/docs/guide/why.md +++ b/docs/guide/why.md @@ -32,7 +32,7 @@ Vite improves the dev server start time by first dividing the modules in an appl When a file is edited in a bundler-based build setup, it is inefficient to rebuild the whole bundle for obvious reasons: the update speed will degrade linearly with the size of the app. -Some bundler dev server runs the bundling in memory so that it only needs to invalidate part of its module graph when a file changes, but it still needs to re-construct the entire bundle and reload the web page. Reconstructing the bundle can be expensive, and reloading the page blows away the current state of the application. This is why some bundlers support Hot Module Replacement (HMR): allowing a module to "hot replace" itself without affecting the rest of the page. This greatly improves DX - however, in practice we've found that even HMR update speed deteriorates significantly as the size of the application grows. +In some bundlers, the dev server runs the bundling in memory so that it only needs to invalidate part of its module graph when a file changes, but it still needs to re-construct the entire bundle and reload the web page. Reconstructing the bundle can be expensive, and reloading the page blows away the current state of the application. This is why some bundlers support Hot Module Replacement (HMR): allowing a module to "hot replace" itself without affecting the rest of the page. This greatly improves DX - however, in practice we've found that even HMR update speed deteriorates significantly as the size of the application grows. In Vite, HMR is performed over native ESM. When a file is edited, Vite only needs to precisely invalidate the chain between the edited module and its closest HMR boundary (most of the time only the module itself), making HMR updates consistently fast regardless of the size of your application. diff --git a/docs/index.md b/docs/index.md index 81b0eb027e8f05..ce1678de00404e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -23,21 +23,16 @@ features: footer: MIT Licensed | Copyright © 2019-present Evan You & Vite Contributors --- -
-

Sponsors

-
- - - -
-
- - - -
- Become a sponsor on GitHub -
- + +

Sponsors

+ + + + + +

+ Become a sponsor on GitHub +

diff --git a/docs/public/finclip.png b/docs/public/finclip.png deleted file mode 100644 index 9110e6d56c164d..00000000000000 Binary files a/docs/public/finclip.png and /dev/null differ diff --git a/package.json b/package.json index 474e355b2f0a12..72b7076ee65d01 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,8 @@ "docs": "vitepress dev docs", "build-docs": "vitepress build docs", "serve-docs": "vitepress serve docs", + "release": "ts-node scripts/release.ts", + "ci-publish": "ts-node scripts/publishCI.ts", "build": "run-s build-vite build-plugin-vue build-plugin-react", "build-vite": "cd packages/vite && npm run build", "build-plugin-vue": "cd packages/plugin-vue && npm run build", @@ -32,41 +34,41 @@ "ci-docs": "run-s build-vite build-plugin-vue build-docs" }, "devDependencies": { - "@microsoft/api-extractor": "^7.19.3", + "@microsoft/api-extractor": "^7.19.4", "@types/fs-extra": "^9.0.13", - "@types/jest": "^27.0.3", - "@types/node": "^16.11.17", + "@types/jest": "^27.4.0", + "@types/node": "^16.11.22", "@types/prompts": "^2.0.14", "@types/semver": "^7.3.9", - "@typescript-eslint/eslint-plugin": "^5.8.1", - "@typescript-eslint/parser": "^5.8.1", + "@typescript-eslint/eslint-plugin": "^5.11.0", + "@typescript-eslint/parser": "^5.11.0", "conventional-changelog-cli": "^2.2.2", "cross-env": "^7.0.3", - "esbuild": "0.14.3", - "eslint": "^8.5.0", - "eslint-define-config": "^1.2.1", + "esbuild": "^0.14.14", + "eslint": "^8.8.0", + "eslint-define-config": "^1.2.4", "eslint-plugin-node": "^11.1.0", "execa": "^5.1.1", "fs-extra": "^10.0.0", - "jest": "^27.4.5", - "lint-staged": "^12.1.4", + "jest": "^27.5.1", + "lint-staged": "^12.3.3", "minimist": "^1.2.5", "node-fetch": "^2.6.6", "npm-run-all": "^4.1.5", "picocolors": "^1.0.0", - "playwright-chromium": "^1.17.1", + "playwright-chromium": "^1.18.1", "prettier": "2.5.1", "prompts": "^2.4.2", "rimraf": "^3.0.2", "rollup": "^2.59.0", "semver": "^7.3.5", "simple-git-hooks": "^2.7.0", - "sirv": "^2.0.0", - "ts-jest": "^27.1.2", + "sirv": "^2.0.2", + "ts-jest": "^27.1.3", "ts-node": "^10.4.0", "typescript": "~4.5.4", "vite": "workspace:*", - "vitepress": "^0.20.10" + "vitepress": "^0.21.6" }, "simple-git-hooks": { "pre-commit": "pnpm exec lint-staged --concurrent false", @@ -83,7 +85,7 @@ "eslint --ext .ts" ] }, - "packageManager": "pnpm@6.24.4", + "packageManager": "pnpm@6.30.0", "pnpm": { "overrides": { "vite": "workspace:*", diff --git a/packages/create-vite/CHANGELOG.md b/packages/create-vite/CHANGELOG.md index 7769233043e03b..b81d7ec6fac49a 100644 --- a/packages/create-vite/CHANGELOG.md +++ b/packages/create-vite/CHANGELOG.md @@ -1,3 +1,17 @@ +# [2.8.0](https://github.com/vitejs/vite/compare/create-vite@2.7.2...create-vite@2.8.0) (2022-02-09) + + +### Bug Fixes + +* **create-vite:** use `reset` for prompts for white bg color shell ([#6131](https://github.com/vitejs/vite/issues/6131)) ([dd3bbb8](https://github.com/vitejs/vite/commit/dd3bbb8e21aff812ec482f760e1abceb6bd67aef)) + + +### Features + +* **create-vite:** tsconfig support vite.config.ts ([#6324](https://github.com/vitejs/vite/issues/6324)) ([bfbdb22](https://github.com/vitejs/vite/commit/bfbdb2242e57cfba0309a88475a1f9cf2a50413f)) + + + ## [2.7.2](https://github.com/vitejs/vite/compare/create-vite@2.7.1...create-vite@2.7.2) (2021-12-13) diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index 3aa6c3fd486814..5d873b83fe515b 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -1,6 +1,6 @@ { "name": "create-vite", - "version": "2.7.2", + "version": "2.8.0", "license": "MIT", "author": "Evan You", "bin": { @@ -12,10 +12,6 @@ "template-*" ], "main": "index.js", - "scripts": { - "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package create-vite", - "release": "ts-node updateVersions && ts-node ../../scripts/release.ts --skipBuild" - }, "engines": { "node": ">=12.0.0" }, diff --git a/packages/create-vite/template-lit-ts/package.json b/packages/create-vite/template-lit-ts/package.json index bd46b90e26456f..5c0a7c7948ee58 100644 --- a/packages/create-vite/template-lit-ts/package.json +++ b/packages/create-vite/template-lit-ts/package.json @@ -1,5 +1,6 @@ { "name": "vite-lit-ts-starter", + "private": true, "version": "0.0.0", "main": "dist/my-element.es.js", "exports": { @@ -18,7 +19,7 @@ "lit": "^2.0.2" }, "devDependencies": { - "vite": "^2.7.2", + "vite": "^2.8.0", "typescript": "^4.5.4" } } diff --git a/packages/create-vite/template-lit/package.json b/packages/create-vite/template-lit/package.json index 1081fd506aa25a..ca3c71428f22c9 100644 --- a/packages/create-vite/template-lit/package.json +++ b/packages/create-vite/template-lit/package.json @@ -1,5 +1,6 @@ { "name": "vite-lit-starter", + "private": true, "version": "0.0.0", "main": "dist/my-element.es.js", "exports": { @@ -16,6 +17,6 @@ "lit": "^2.0.2" }, "devDependencies": { - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-preact-ts/package.json b/packages/create-vite/template-preact-ts/package.json index e7553e47fcc753..df1726ba6c4f7b 100644 --- a/packages/create-vite/template-preact-ts/package.json +++ b/packages/create-vite/template-preact-ts/package.json @@ -1,5 +1,6 @@ { "name": "vite-preact-ts-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -12,6 +13,6 @@ "devDependencies": { "@preact/preset-vite": "^2.1.5", "typescript": "^4.5.4", - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-preact/package.json b/packages/create-vite/template-preact/package.json index dcfc501e7f2c24..2865df70374acf 100644 --- a/packages/create-vite/template-preact/package.json +++ b/packages/create-vite/template-preact/package.json @@ -1,5 +1,6 @@ { "name": "vite-preact-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -11,6 +12,6 @@ }, "devDependencies": { "@preact/preset-vite": "^2.1.5", - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-react-ts/package.json b/packages/create-vite/template-react-ts/package.json index c7d38bd544c646..3b1e21b7dbca8c 100644 --- a/packages/create-vite/template-react-ts/package.json +++ b/packages/create-vite/template-react-ts/package.json @@ -1,5 +1,6 @@ { "name": "vite-react-typescript-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -15,6 +16,6 @@ "@types/react-dom": "^17.0.10", "@vitejs/plugin-react": "^1.0.7", "typescript": "^4.5.4", - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-react/package.json b/packages/create-vite/template-react/package.json index e9a2984db1960a..7b0f87c6bc95f5 100644 --- a/packages/create-vite/template-react/package.json +++ b/packages/create-vite/template-react/package.json @@ -1,5 +1,6 @@ { "name": "vite-react-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -12,6 +13,6 @@ }, "devDependencies": { "@vitejs/plugin-react": "^1.0.7", - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-svelte-ts/package.json b/packages/create-vite/template-svelte-ts/package.json index f89fc6a68fcf7c..3f2c63759285e5 100644 --- a/packages/create-vite/template-svelte-ts/package.json +++ b/packages/create-vite/template-svelte-ts/package.json @@ -1,5 +1,6 @@ { "name": "vite-svelte-ts-starter", + "private": true, "version": "0.0.0", "type": "module", "scripts": { @@ -16,6 +17,6 @@ "svelte-preprocess": "^4.9.8", "tslib": "^2.3.1", "typescript": "^4.5.4", - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-svelte/package.json b/packages/create-vite/template-svelte/package.json index 4a4ac5796dae47..e81ffa8288b6ef 100644 --- a/packages/create-vite/template-svelte/package.json +++ b/packages/create-vite/template-svelte/package.json @@ -1,5 +1,6 @@ { "name": "vite-svelte-starter", + "private": true, "version": "0.0.0", "type": "module", "scripts": { @@ -10,6 +11,6 @@ "devDependencies": { "@sveltejs/vite-plugin-svelte": "^1.0.0-next.30", "svelte": "^3.44.0", - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-vanilla-ts/package.json b/packages/create-vite/template-vanilla-ts/package.json index 565e7e254beab8..9b6cc582bfdb11 100644 --- a/packages/create-vite/template-vanilla-ts/package.json +++ b/packages/create-vite/template-vanilla-ts/package.json @@ -1,5 +1,6 @@ { "name": "vite-typescript-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -8,6 +9,6 @@ }, "devDependencies": { "typescript": "^4.5.4", - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-vanilla/package.json b/packages/create-vite/template-vanilla/package.json index e8dc2c73fc5388..f409412bbdc272 100644 --- a/packages/create-vite/template-vanilla/package.json +++ b/packages/create-vite/template-vanilla/package.json @@ -1,5 +1,6 @@ { "name": "vite-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -7,6 +8,6 @@ "preview": "vite preview" }, "devDependencies": { - "vite": "^2.7.2" + "vite": "^2.8.0" } } diff --git a/packages/create-vite/template-vue-ts/package.json b/packages/create-vite/template-vue-ts/package.json index abf8b8fe976506..14c6214460dd9e 100644 --- a/packages/create-vite/template-vue-ts/package.json +++ b/packages/create-vite/template-vue-ts/package.json @@ -1,5 +1,6 @@ { "name": "vite-vue-typescript-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -10,9 +11,9 @@ "vue": "^3.2.25" }, "devDependencies": { - "@vitejs/plugin-vue": "^2.0.0", + "@vitejs/plugin-vue": "^2.2.0", "typescript": "^4.5.4", - "vite": "^2.7.2", + "vite": "^2.8.0", "vue-tsc": "^0.29.8" } } diff --git a/packages/create-vite/template-vue/package.json b/packages/create-vite/template-vue/package.json index 6d2e335a7ac937..3136fcda2a0bc7 100644 --- a/packages/create-vite/template-vue/package.json +++ b/packages/create-vite/template-vue/package.json @@ -1,5 +1,6 @@ { "name": "vite-vue-starter", + "private": true, "version": "0.0.0", "scripts": { "dev": "vite", @@ -10,7 +11,7 @@ "vue": "^3.2.25" }, "devDependencies": { - "@vitejs/plugin-vue": "^2.0.0", - "vite": "^2.7.2" + "@vitejs/plugin-vue": "^2.2.0", + "vite": "^2.8.0" } } diff --git a/packages/create-vite/updateVersions.ts b/packages/create-vite/updateVersions.ts deleted file mode 100644 index 7125fce9119f07..00000000000000 --- a/packages/create-vite/updateVersions.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { readdirSync, writeFileSync } from 'fs' -import { join } from 'path' - -const latestVersion = require('../vite/package.json').version -const isLatestPreRelease = /beta|alpha|rc/.test(latestVersion) - -;(async () => { - const templates = readdirSync(__dirname).filter((dir) => - dir.startsWith('template-') - ) - for (const template of templates) { - const pkgPath = join(__dirname, template, `package.json`) - const pkg = require(pkgPath) - if (!isLatestPreRelease) { - pkg.devDependencies.vite = `^` + latestVersion - } - if (template.startsWith('template-vue')) { - pkg.devDependencies['@vitejs/plugin-vue'] = - `^` + require('../plugin-vue/package.json').version - } - writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n') - } -})() diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index c51bb4094b7b8c..191da897858dd5 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -120,6 +120,10 @@ describe('css url() references', () => { const match = isBuild ? `data:image/png;base64` : `/foo/nested/icon.png` expect(await getBg('.css-url-base64-inline')).toMatch(match) expect(await getBg('.css-url-quotes-base64-inline')).toMatch(match) + const icoMatch = isBuild ? `data:image/x-icon;base64` : `favicon.ico` + const el = await page.$(`link.ico`) + const herf = await el.getAttribute('href') + expect(herf).toMatch(icoMatch) }) test('multiple urls on the same line', async () => { diff --git a/packages/playground/assets/favicon.ico b/packages/playground/assets/favicon.ico new file mode 100644 index 00000000000000..d75d248ef0b150 Binary files /dev/null and b/packages/playground/assets/favicon.ico differ diff --git a/packages/playground/assets/index.html b/packages/playground/assets/index.html index f3b9a0b372a608..e33e9a7cdaaf7d 100644 --- a/packages/playground/assets/index.html +++ b/packages/playground/assets/index.html @@ -2,6 +2,7 @@ + @@ -137,6 +138,14 @@

new URL('...', import.meta.url)

+

new URL('...', import.meta.url,) (with comma)

+ + + +

new URL('...', import.meta.url,) (with comma + new line)

+ + +

new URL(`./${dynamic}`, import.meta.url)

@@ -147,6 +156,16 @@

new URL(`./${dynamic}`, import.meta.url)

+

new URL(`./${dynamic}`, import.meta.url,) (with comma)

+

+ + +

+

+ + +

+

simple script tag import-expression

diff --git a/packages/playground/env-nested/package.json b/packages/playground/env-nested/package.json new file mode 100644 index 00000000000000..8fecc69a41c2f4 --- /dev/null +++ b/packages/playground/env-nested/package.json @@ -0,0 +1,11 @@ +{ + "name": "test-env-nested", + "private": true, + "version": "0.0.0", + "scripts": { + "dev": "vite", + "build": "vite build", + "debug": "node --inspect-brk ../../vite/bin/vite", + "preview": "vite preview" + } +} diff --git a/packages/playground/env-nested/vite.config.js b/packages/playground/env-nested/vite.config.js new file mode 100644 index 00000000000000..0e46100698650d --- /dev/null +++ b/packages/playground/env-nested/vite.config.js @@ -0,0 +1,5 @@ +const { defineConfig } = require('vite') + +module.exports = defineConfig({ + envDir: './envs' +}) diff --git a/packages/playground/fs-serve/root/src/index.html b/packages/playground/fs-serve/root/src/index.html index c8b294e86ab0ea..9e4f728a593a91 100644 --- a/packages/playground/fs-serve/root/src/index.html +++ b/packages/playground/fs-serve/root/src/index.html @@ -8,6 +8,10 @@

Safe Fetch


 

 
+

Safe Fetch Subdirectory

+

+

+
 

Unsafe Fetch


 

@@ -42,6 +46,15 @@ 

Denied

.then((data) => { text('.safe-fetch', JSON.stringify(data)) }) + // inside allowed dir, safe fetch + fetch('/src/subdir/safe.txt') + .then((r) => { + text('.safe-fetch-subdir-status', r.status) + return r.text() + }) + .then((data) => { + text('.safe-fetch-subdir', JSON.stringify(data)) + }) // outside of allowed dir, treated as unsafe fetch('/unsafe.txt') diff --git a/packages/playground/fs-serve/root/src/subdir/safe.txt b/packages/playground/fs-serve/root/src/subdir/safe.txt new file mode 100644 index 00000000000000..3f3d0607101642 --- /dev/null +++ b/packages/playground/fs-serve/root/src/subdir/safe.txt @@ -0,0 +1 @@ +KEY=safe diff --git a/packages/playground/html/__tests__/html.spec.ts b/packages/playground/html/__tests__/html.spec.ts index 1a663efb146977..66f537e5026361 100644 --- a/packages/playground/html/__tests__/html.spec.ts +++ b/packages/playground/html/__tests__/html.spec.ts @@ -197,25 +197,6 @@ describe('noBody', () => { }) }) -describe('importAsString', () => { - // The build-html plugin should not alter HTML that is not an input. - test('not transformed', async () => { - const messages = [] - function addConsoleMessage(message) { - messages.push(message.args()[0]) - } - - page.on('console', addConsoleMessage) - await page.goto(viteTestUrl + '/index.html') - await page.waitForLoadState() - page.off('console', addConsoleMessage) - - const result = messages.map((m) => m.toString()).join('\n') - expect(result).toMatch('Some imported HTML') - expect(result).not.toMatch('This is injected') - }) -}) - describe('unicode path', () => { test('direct access', async () => { await page.goto( diff --git a/packages/playground/html/importAsString.html b/packages/playground/html/importAsString.html deleted file mode 100644 index a9f57d697bef91..00000000000000 --- a/packages/playground/html/importAsString.html +++ /dev/null @@ -1,5 +0,0 @@ - - - Some imported HTML - - diff --git a/packages/playground/html/main.js b/packages/playground/html/main.js index c44ec322c965f7..cd769880553ced 100644 --- a/packages/playground/html/main.js +++ b/packages/playground/html/main.js @@ -1,6 +1,4 @@ import { msg } from './shared' -import asString from './importAsString.html' import './common.css' console.log(msg + ' from main') -console.log('loaded string ' + asString) diff --git a/packages/playground/html/vite.config.js b/packages/playground/html/vite.config.js index 7dc01af7d9ca79..1703e02cc05366 100644 --- a/packages/playground/html/vite.config.js +++ b/packages/playground/html/vite.config.js @@ -157,18 +157,6 @@ ${ } ] } - }, - { - // Emulate rollup-plugin-string - name: 'import-as-string-module', - transform(code, id) { - if (id.endsWith('importAsString.html')) { - return { - code: `export default ${JSON.stringify(code)}`, - map: { mappings: '' } - } - } - } } ] } diff --git a/packages/playground/json/index.html b/packages/playground/json/index.html index 4f6e2b6ae57466..cf16636f91cb68 100644 --- a/packages/playground/json/index.html +++ b/packages/playground/json/index.html @@ -19,6 +19,9 @@

Importing as URL

Raw Import


 
+

JSON Module

+

+
 
+
+
diff --git a/packages/playground/vue-jsx/vite.config.js b/packages/playground/vue-jsx/vite.config.js
index 3ec89a003d79f4..d6eb84e05f4e4a 100644
--- a/packages/playground/vue-jsx/vite.config.js
+++ b/packages/playground/vue-jsx/vite.config.js
@@ -9,7 +9,28 @@ module.exports = {
     vueJsxPlugin({
       include: [/\.tesx$/, /\.[jt]sx$/]
     }),
-    vuePlugin()
+    vuePlugin(),
+    {
+      name: 'jsx-query-plugin',
+      transform(code, id) {
+        if (id.includes('?query=true')) {
+          return `
+import { createVNode as _createVNode } from "vue";
+import { defineComponent, ref } from 'vue';
+export default defineComponent(() => {
+  const count = ref(6);
+
+  const inc = () => count.value++;
+
+  return () => _createVNode("button", {
+    "class": "jsx-with-query",
+    "onClick": inc
+  }, [count.value]);
+});
+`
+        }
+      }
+    }
   ],
   build: {
     // to make tests faster
diff --git a/packages/playground/vue/ExternalStyleCss.vue b/packages/playground/vue/ExternalStyleCss.vue
deleted file mode 100644
index f58e3cd5c697a7..00000000000000
--- a/packages/playground/vue/ExternalStyleCss.vue
+++ /dev/null
@@ -1 +0,0 @@
-
diff --git a/packages/playground/vue/Main.vue b/packages/playground/vue/Main.vue
index ea14dc8f481b86..d10ae401f7aa8e 100644
--- a/packages/playground/vue/Main.vue
+++ b/packages/playground/vue/Main.vue
@@ -20,7 +20,6 @@
   
   
   
-