From 3e23e6c1e0b41f26a70c53f9e9f60b4db5c76424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 15 Nov 2022 00:48:51 +0900 Subject: [PATCH] fix(vue): skip url query request (fixes #10863) (#10920) fixes https://github.com/vitejs/vite/issues/10863 --- packages/plugin-vue/src/index.ts | 2 +- packages/plugin-vue/src/utils/query.ts | 4 ++++ playground/vue/Main.vue | 2 ++ playground/vue/Null.vue | 1 + playground/vue/Url.vue | 10 ++++++++++ playground/vue/__tests__/vue.spec.ts | 8 ++++++++ playground/vue/tsconfig.json | 2 +- playground/vue/vite-env.d.ts | 1 + 8 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 playground/vue/Null.vue create mode 100644 playground/vue/Url.vue create mode 100644 playground/vue/vite-env.d.ts diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index e8763443..d1067b58 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -207,7 +207,7 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { transform(code, id, opt) { const ssr = opt?.ssr === true const { filename, query } = parseVueRequest(id) - if (query.raw) { + if (query.raw || query.url) { return } if (!filter(filename) && !query.vue) { diff --git a/packages/plugin-vue/src/utils/query.ts b/packages/plugin-vue/src/utils/query.ts index f579067e..5bdb0dbb 100644 --- a/packages/plugin-vue/src/utils/query.ts +++ b/packages/plugin-vue/src/utils/query.ts @@ -5,6 +5,7 @@ export interface VueQuery { index?: number lang?: string raw?: boolean + url?: boolean scoped?: boolean } @@ -23,6 +24,9 @@ export function parseVueRequest(id: string): { if (query.raw != null) { query.raw = true } + if (query.url != null) { + query.url = true + } if (query.scoped != null) { query.scoped = true } diff --git a/playground/vue/Main.vue b/playground/vue/Main.vue index c5f3d274..521bbbff 100644 --- a/playground/vue/Main.vue +++ b/playground/vue/Main.vue @@ -22,6 +22,7 @@ + + + diff --git a/playground/vue/__tests__/vue.spec.ts b/playground/vue/__tests__/vue.spec.ts index 51dbf82a..2fe537e6 100644 --- a/playground/vue/__tests__/vue.spec.ts +++ b/playground/vue/__tests__/vue.spec.ts @@ -263,3 +263,11 @@ describe('vue worker', () => { expect(await page.textContent('.vue-worker')).toMatch('worker load!') }) }) + +describe('import with ?url', () => { + test('should work', async () => { + expect(await page.textContent('.import-with-url-query')).toMatch( + isBuild ? /^data:/ : '/Null.vue' + ) + }) +}) diff --git a/playground/vue/tsconfig.json b/playground/vue/tsconfig.json index 5f90cb16..bdc0eedc 100644 --- a/playground/vue/tsconfig.json +++ b/playground/vue/tsconfig.json @@ -3,5 +3,5 @@ // esbuild transpile should ignore this "target": "ES5" }, - "include": ["src"] + "include": ["."] } diff --git a/playground/vue/vite-env.d.ts b/playground/vue/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/playground/vue/vite-env.d.ts @@ -0,0 +1 @@ +///