From 5818ac927861783ea2b05450761fed30f40e7399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Seery?= Date: Sat, 26 Feb 2022 04:49:34 -0300 Subject: [PATCH 01/42] fix: ?html-proxy with trailing = added by some servers (#7093) --- packages/vite/src/node/plugins/html.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/plugins/html.ts b/packages/vite/src/node/plugins/html.ts index e7ca5e63961253..7f8a750c72bf22 100644 --- a/packages/vite/src/node/plugins/html.ts +++ b/packages/vite/src/node/plugins/html.ts @@ -41,7 +41,7 @@ interface ScriptAssetsUrl { url: string } -const htmlProxyRE = /\?html-proxy[&inline\-css]*&index=(\d+)\.(js|css)$/ +const htmlProxyRE = /\?html-proxy=?[&inline\-css]*&index=(\d+)\.(js|css)$/ const inlineCSSRE = /__VITE_INLINE_CSS__([^_]+_\d+)__/g const inlineImportRE = /\bimport\s*\(("[^"]*"|'[^']*')\)/g export const isHTMLProxy = (id: string): boolean => htmlProxyRE.test(id) From 30125418b4c7ebda56555090b177ac34b29ffdc7 Mon Sep 17 00:00:00 2001 From: ygj6 <7699524+ygj6@users.noreply.github.com> Date: Sun, 27 Feb 2022 00:52:43 +0800 Subject: [PATCH 02/42] fix(ssrTransform): use appendLeft instead of appendRight (#6407) --- .../node/ssr/__tests__/ssrTransform.spec.ts | 34 ++++++++++++++++--- packages/vite/src/node/ssr/ssrTransform.ts | 2 +- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts index f91444b49636a1..e086365ee25f16 100644 --- a/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts +++ b/packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts @@ -304,8 +304,8 @@ test('should declare variable for imported super class', async () => { const Foo = __vite_ssr_import_0__.Foo; class A extends Foo {} class B extends Foo {} - Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A }); - Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});" + Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }}); + Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A });" `) }) @@ -351,8 +351,8 @@ test('should handle default export variants', async () => { ).toMatchInlineSnapshot(` "class A {} class B extends A {} - Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A }); - Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }});" + Object.defineProperty(__vite_ssr_exports__, \\"B\\", { enumerable: true, configurable: true, get(){ return B }}); + Object.defineProperty(__vite_ssr_exports__, \\"default\\", { enumerable: true, value: A });" `) }) @@ -610,7 +610,7 @@ test('jsx', async () => { const code = ` import React from 'react' import { Foo, Slot } from 'foo' - + function Bar({ Slot = }) { return ( <> @@ -633,3 +633,27 @@ test('jsx', async () => { " `) }) + +test('continuous exports', async () => { + expect( + ( + await ssrTransform( + ` +export function fn1() { +}export function fn2() { +} + `, + null, + null + ) + ).code + ).toMatchInlineSnapshot(` + " + function fn1() { + } + Object.defineProperty(__vite_ssr_exports__, \\"fn1\\", { enumerable: true, configurable: true, get(){ return fn1 }});function fn2() { + } + Object.defineProperty(__vite_ssr_exports__, \\"fn2\\", { enumerable: true, configurable: true, get(){ return fn2 }}); + " + `) +}) diff --git a/packages/vite/src/node/ssr/ssrTransform.ts b/packages/vite/src/node/ssr/ssrTransform.ts index b4eee713e707bc..36496b8168ad36 100644 --- a/packages/vite/src/node/ssr/ssrTransform.ts +++ b/packages/vite/src/node/ssr/ssrTransform.ts @@ -66,7 +66,7 @@ export async function ssrTransform( } function defineExport(position: number, name: string, local = name) { - s.appendRight( + s.appendLeft( position, `\nObject.defineProperty(${ssrModuleExportsKey}, "${name}", ` + `{ enumerable: true, configurable: true, get(){ return ${local} }});` From 79428ad5b849455e14f95d1b439ae296ba231221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Volf?= Date: Sun, 27 Feb 2022 05:02:14 +0100 Subject: [PATCH 03/42] fix(config): Warn about terserOptions in more cases (#7101) --- packages/vite/src/node/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index fbda8d5166cb1b..224c534c497ece 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -649,7 +649,7 @@ export async function resolveConfig( ) } - if (config.build?.terserOptions && config.build.minify === 'esbuild') { + if (config.build?.terserOptions && config.build.minify !== 'terser') { logger.warn( colors.yellow( `build.terserOptions is specified but build.minify is not set to use Terser. ` + From 7a1a552ba710bad5714ef0fbb16fdd29ac58ae0b Mon Sep 17 00:00:00 2001 From: yoho <907415276@qq.com> Date: Sun, 27 Feb 2022 19:56:00 +0800 Subject: [PATCH 04/42] fix: fileToBuiltUrl got undefined when file type is `.ico` (#7106) --- .../playground/assets/__tests__/assets.spec.ts | 4 ++++ packages/playground/assets/favicon.ico | Bin 0 -> 1150 bytes packages/playground/assets/index.html | 1 + packages/vite/src/node/plugins/asset.ts | 4 ++++ 4 files changed, 9 insertions(+) create mode 100644 packages/playground/assets/favicon.ico diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index dfdd8099b062a2..8781fec785f3f2 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -121,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;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 0000000000000000000000000000000000000000..d75d248ef0b15096a95054643a4d97f5d9b60846 GIT binary patch literal 1150 zcmaKqSxA*Z7>4KMS_;~x;8i!JU{-`tpyx!I(n2NFMU)w2L{WiMS3#Lcp@vrpA*5Yp zSy6|`AkYfDD(e{`n8yX0pLf20X1@3RmKkGw`Vte3=0)aUq%ldx zm^49K+Hw0b#^`KboP)QXJOwbuVUFxlAs{RfqJ+twGylWfOp{Hc$s#253LlN1nsFVc zKa>40?h5(7PTC6ltDx)(Y&Ze2xggCq(kK? zTA`;gAfKD!+uFjpxc_A3+Ma(L28W=z4Gvs@r*ECk`;c45=S#;=oA|abt`f&j5&uJO z3Dn+&^gZ%h4JidsaTR{{!_Y8PUx(-%PosPy2gi@qIvBMMYz;e3L1{f~mrd9RdB>pZ zD}4R|sk_C`;=cT&r)c=8u>7h9)u32*SbL`xiq3(pq5C^5-sSOw;<|fv@nfXfl&U`2 z81K5ExDp;bf#DISW%IY%k&2-noShOoz-;kb(u?5RFX-ro?87j3GZdCXrFc8bTx}jd zz_n@djWnxc*TbbCjEq80FPyG}1zQwvjq7R6ZSWuQ@_#A*LN5n<3$BI?X}q%iD!B-s zdSFcNp!EgpJr6CAK?klug4>=)Tv z+F#{yt>6EK)3NU=L&y_W3UNaC?Tg=6YE0)^V;(0Mb0$WJ7>7@Lg0~+3x9d)!Pd + diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 7ec3a01543f9a4..0b859183f6f8f3 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -33,6 +33,10 @@ const emittedHashMap = new WeakMap>() export function assetPlugin(config: ResolvedConfig): Plugin { // assetHashToFilenameMap initialization in buildStart causes getAssetFilename to return undefined assetHashToFilenameMap.set(config, new Map()) + + // add own dictionary entry by directly assigning mrmine + // https://github.com/lukeed/mrmime/issues/3 + mrmime.mimes['ico'] = 'image' return { name: 'vite:asset', From 1bd54caa098d81f6ecec1cee7e99a6a7ac7b7f88 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 28 Feb 2022 09:23:05 +0100 Subject: [PATCH 05/42] chore(deps): update actions/setup-node action to v3 (#7113) --- .github/workflows/ci.yml | 4 ++-- .github/workflows/publish.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3954ca49c11479..69ba432050fa7e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,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" @@ -82,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/publish.yml b/.github/workflows/publish.yml index eb8f4513707872..9e22af5aed6ee8 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,7 +23,7 @@ jobs: version: 6 - name: Set node version to 16.x - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: 16.x registry-url: https://registry.npmjs.org/ From 065ceca5c7b8f1843e220fbdbe8a0da4cbb78935 Mon Sep 17 00:00:00 2001 From: yoho <907415276@qq.com> Date: Mon, 28 Feb 2022 18:45:20 +0800 Subject: [PATCH 06/42] fix: image -> image/x-icon (#7120) --- packages/playground/assets/__tests__/assets.spec.ts | 2 +- packages/vite/src/node/plugins/asset.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/playground/assets/__tests__/assets.spec.ts b/packages/playground/assets/__tests__/assets.spec.ts index 8781fec785f3f2..8efbf1fcc2f082 100644 --- a/packages/playground/assets/__tests__/assets.spec.ts +++ b/packages/playground/assets/__tests__/assets.spec.ts @@ -121,7 +121,7 @@ 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;base64` : `favicon.ico` + 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) diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 0b859183f6f8f3..3c7681ad6f0bb8 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -36,7 +36,7 @@ export function assetPlugin(config: ResolvedConfig): Plugin { // add own dictionary entry by directly assigning mrmine // https://github.com/lukeed/mrmime/issues/3 - mrmime.mimes['ico'] = 'image' + mrmime.mimes['ico'] = 'image/x-icon' return { name: 'vite:asset', From 66cafca61c8eefe67c8371249a2fc6e043b91e43 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Tue, 1 Mar 2022 00:06:04 +0800 Subject: [PATCH 07/42] fix(vue-jsx): support jsx imports with queries (#7121) --- packages/playground/vue-jsx/Query.jsx | 12 ++++++++++ .../vue-jsx/__tests__/vue-jsx.spec.ts | 3 +++ packages/playground/vue-jsx/main.jsx | 4 ++++ packages/playground/vue-jsx/vite.config.js | 23 ++++++++++++++++++- packages/plugin-vue-jsx/index.js | 7 ++++-- 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 packages/playground/vue-jsx/Query.jsx diff --git a/packages/playground/vue-jsx/Query.jsx b/packages/playground/vue-jsx/Query.jsx new file mode 100644 index 00000000000000..60de93eafb7b1c --- /dev/null +++ b/packages/playground/vue-jsx/Query.jsx @@ -0,0 +1,12 @@ +import { defineComponent, ref } from 'vue' + +export default defineComponent(() => { + const count = ref(6) + const inc = () => count.value++ + + return () => ( + + ) +}) diff --git a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts index 64327e64a5f263..999fdc19af51ec 100644 --- a/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts +++ b/packages/playground/vue-jsx/__tests__/vue-jsx.spec.ts @@ -7,6 +7,7 @@ test('should render', async () => { expect(await page.textContent('.default-tsx')).toMatch('3') expect(await page.textContent('.script')).toMatch('4') expect(await page.textContent('.src-import')).toMatch('5') + expect(await page.textContent('.jsx-with-query')).toMatch('6') expect(await page.textContent('.other-ext')).toMatch('Other Ext') }) @@ -23,6 +24,8 @@ test('should update', async () => { expect(await page.textContent('.script')).toMatch('5') await page.click('.src-import') expect(await page.textContent('.src-import')).toMatch('6') + await page.click('.jsx-with-query') + expect(await page.textContent('.jsx-with-query')).toMatch('7') }) if (!isBuild) { diff --git a/packages/playground/vue-jsx/main.jsx b/packages/playground/vue-jsx/main.jsx index 1a792ea55d2a3c..e304e7788e49e7 100644 --- a/packages/playground/vue-jsx/main.jsx +++ b/packages/playground/vue-jsx/main.jsx @@ -5,6 +5,9 @@ import OtherExt from './OtherExt.tesx' import JsxScript from './Script.vue' import JsxSrcImport from './SrcImport.vue' import JsxSetupSyntax from './setup-syntax-jsx.vue' +// eslint-disable-next-line +import JsxWithQuery from './Query.jsx?query=true' + function App() { return ( <> @@ -16,6 +19,7 @@ function App() { + ) } 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/plugin-vue-jsx/index.js b/packages/plugin-vue-jsx/index.js index 56c50fe2ff5e6d..248270765d19a1 100644 --- a/packages/plugin-vue-jsx/index.js +++ b/packages/plugin-vue-jsx/index.js @@ -95,10 +95,13 @@ function vueJsxPlugin(options = {}) { } = options const filter = createFilter(include || /\.[jt]sx$/, exclude) + const [filepath] = id.split('?') - if (filter(id)) { + // use id for script blocks in Vue SFCs (e.g. `App.vue?vue&type=script&lang.jsx`) + // use filepath for plain jsx files (e.g. App.jsx) + if (filter(id) || filter(filepath)) { const plugins = [importMeta, [jsx, babelPluginOptions], ...babelPlugins] - if (id.endsWith('.tsx')) { + if (id.endsWith('.tsx') || filepath.endsWith('.tsx')) { plugins.push([ require('@babel/plugin-transform-typescript'), // @ts-ignore From 22a0381e5e791296ffa7758331d95ae8ca870acd Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 28 Feb 2022 17:35:18 +0100 Subject: [PATCH 08/42] release: v2.8.5 --- packages/vite/CHANGELOG.md | 29 +++++++++++++++++++++++++++++ packages/vite/package.json | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/vite/CHANGELOG.md b/packages/vite/CHANGELOG.md index c2f9a3f62ed9f0..711fdfb3026df8 100644 --- a/packages/vite/CHANGELOG.md +++ b/packages/vite/CHANGELOG.md @@ -1,3 +1,32 @@ +## [2.8.5](https://github.com/vitejs/vite/compare/v2.8.4...v2.8.5) (2022-02-28) + + +### Bug Fixes + +* ?html-proxy with trailing = added by some servers ([#7093](https://github.com/vitejs/vite/issues/7093)) ([5818ac9](https://github.com/vitejs/vite/commit/5818ac927861783ea2b05450761fed30f40e7399)) +* allow optional trailing comma in asset `import.meta.url` ([#6983](https://github.com/vitejs/vite/issues/6983)) ([2debb9f](https://github.com/vitejs/vite/commit/2debb9f4cbb6003e7d24444cf049b45582d82ff1)) +* cannot reassign process.env.NODE_ENV in ssr ([#6989](https://github.com/vitejs/vite/issues/6989)) ([983feb2](https://github.com/vitejs/vite/commit/983feb2cdc5180dc46c3f5fc5b99baaa8d6b7078)) +* **config:** Warn about terserOptions in more cases ([#7101](https://github.com/vitejs/vite/issues/7101)) ([79428ad](https://github.com/vitejs/vite/commit/79428ad5b849455e14f95d1b439ae296ba231221)) +* don't override user config ([#7034](https://github.com/vitejs/vite/issues/7034)) ([8fd8f6e](https://github.com/vitejs/vite/commit/8fd8f6e0e501c9e46bc3e179c900d31fa5cafce1)) +* fileToBuiltUrl got undefined when file type is `.ico` ([#7106](https://github.com/vitejs/vite/issues/7106)) ([7a1a552](https://github.com/vitejs/vite/commit/7a1a552ba710bad5714ef0fbb16fdd29ac58ae0b)) +* **glob:** css imports injecting a ?used query to export the css string ([#6949](https://github.com/vitejs/vite/issues/6949)) ([0b3f4ef](https://github.com/vitejs/vite/commit/0b3f4ef231004e072bf1b037f63bc4ef169d938e)) +* **hmr:** hmr style tag no support in html ([#7052](https://github.com/vitejs/vite/issues/7052)) ([a9dfce3](https://github.com/vitejs/vite/commit/a9dfce38108e796e0de0e3b43ced34d60883cef3)) +* image -> image/x-icon ([#7120](https://github.com/vitejs/vite/issues/7120)) ([065ceca](https://github.com/vitejs/vite/commit/065ceca5c7b8f1843e220fbdbe8a0da4cbb78935)) +* import with query with exports field ([#7073](https://github.com/vitejs/vite/issues/7073)) ([88ded7f](https://github.com/vitejs/vite/commit/88ded7f16382d83603511de043785e01ee1e4a3a)) +* prebundle dep with colon ([#7006](https://github.com/vitejs/vite/issues/7006)) ([2136f2b](https://github.com/vitejs/vite/commit/2136f2bb960d1a81ac3b3ca04d9ebd89dba44661)) +* recycle serve to avoid preventing Node self-exit ([#6895](https://github.com/vitejs/vite/issues/6895)) ([d6b2c53](https://github.com/vitejs/vite/commit/d6b2c53c6f0bcc4ffa9cdf48375f9bbcc98f79f7)) +* resolve [@import](https://github.com/import) of the proxied