From 1967c6a8bac8084c66ee20e29a42bd79053e1749 Mon Sep 17 00:00:00 2001 From: sapphi-red Date: Mon, 14 Nov 2022 22:58:21 +0900 Subject: [PATCH] fix(vue): skip url query request (fixes #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 e8763443d032c0..d1067b5811f5f3 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 f579067e52f8d8..5bdb0dbb93aa07 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 c5f3d27402fda7..521bbbff08a3ce 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 51dbf82a480aff..2fe537e6135a00 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 5f90cb166d696b..bdc0eedc2244af 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 00000000000000..11f02fe2a0061d --- /dev/null +++ b/playground/vue/vite-env.d.ts @@ -0,0 +1 @@ +///