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 + +
+ + + +
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 @@ + + + + + ++ 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 63c7e38d0d0652..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", diff --git a/packages/create-vite/package.json b/packages/create-vite/package.json index 6ff118b7793840..5d873b83fe515b 100644 --- a/packages/create-vite/package.json +++ b/packages/create-vite/package.json @@ -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-vue-ts/README.md b/packages/create-vite/template-vue-ts/README.md index f5342b7d8f66dd..b53dcfb1a715e6 100644 --- a/packages/create-vite/template-vue-ts/README.md +++ b/packages/create-vite/template-vue-ts/README.md @@ -8,4 +8,9 @@ This template should help get you started developing with Vue 3 and Typescript i ## Type Support For `.vue` Imports in TS -Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's `.vue` type support plugin by running `Volar: Switch TS Plugin on/off` from VSCode command palette. +Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps: + +1. Run `Extensions: Show Built-in Extensions` from VSCode's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled. +2. Reload the VSCode window by running `Developer: Reload Window` from the command palette. + +You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471). diff --git a/packages/create-vite/template-vue-ts/tsconfig.json b/packages/create-vite/template-vue-ts/tsconfig.json index af31eb8152d3cb..52205ea0029c99 100644 --- a/packages/create-vite/template-vue-ts/tsconfig.json +++ b/packages/create-vite/template-vue-ts/tsconfig.json @@ -8,6 +8,7 @@ "jsx": "preserve", "sourceMap": true, "resolveJsonModule": true, + "isolatedModules": true, "esModuleInterop": true, "lib": ["esnext", "dom"] }, 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..0635236bd7369e 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -8,7 +8,8 @@ import { readManifest, readFile, editFile, - notifyRebuildComplete + notifyRebuildComplete, + untilUpdated } from '../../testUtils' const assetMatch = isBuild @@ -37,7 +38,7 @@ describe('injected scripts', () => { test('html-proxy', async () => { const hasHtmlProxy = await page.$( - 'script[type="module"][src="/foo/index.html?html-proxy&index=0.js"]' + 'script[type="module"][src^="/foo/index.html?html-proxy"]' ) if (isBuild) { expect(hasHtmlProxy).toBeFalsy() @@ -120,6 +121,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 () => { @@ -228,6 +233,12 @@ test('new URL(`${dynamic}`, import.meta.url)', async () => { ) }) +test('new URL(`non-existent`, import.meta.url)', async () => { + expect(await page.textContent('.non-existent-import-meta-url')).toMatch( + '/foo/non-existent' + ) +}) + if (isBuild) { test('manifest', async () => { const manifest = readManifest('foo') @@ -254,3 +265,15 @@ describe('css and assets in css in build watch', () => { }) } }) + +if (!isBuild) { + test('@import in html style tag hmr', async () => { + await untilUpdated(() => getColor('.import-css'), 'rgb(0, 136, 255)') + editFile( + './css/import.css', + (code) => code.replace('#0088ff', '#00ff88'), + true + ) + await untilUpdated(() => getColor('.import-css'), 'rgb(0, 255, 136)') + }) +} 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..25c889a445b771 100644 --- a/packages/playground/assets/index.html +++ b/packages/playground/assets/index.html @@ -2,6 +2,7 @@ + @@ -137,6 +138,14 @@
+
+
+
+
@@ -147,6 +156,21 @@
+
+
+
+
+
+
+
+
+
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 @@ fail
+fail
+fail
@@ -38,6 +41,17 @@fail
+fail
+ +fail
+fail
@@ -100,6 +114,10 @@{{ count }}
+