Skip to content

Commit

Permalink
fix(vue): skip url query request (fixes #10863) (#10920)
Browse files Browse the repository at this point in the history
fixes #10863
  • Loading branch information
sapphi-red committed Nov 14, 2022
1 parent fc007df commit 97d200c
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-vue/src/index.ts
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-vue/src/utils/query.ts
Expand Up @@ -5,6 +5,7 @@ export interface VueQuery {
index?: number
lang?: string
raw?: boolean
url?: boolean
scoped?: boolean
}

Expand All @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions playground/vue/Main.vue
Expand Up @@ -22,6 +22,7 @@
<ReactivityTransform :foo="time" />
<SetupImportTemplate />
<WorkerTest />
<Url />
</template>

<script setup lang="ts">
Expand All @@ -40,6 +41,7 @@ import ReactivityTransform from './ReactivityTransform.vue'
import SetupImportTemplate from './setup-import-template/SetupImportTemplate.vue'
import WorkerTest from './worker.vue'
import { ref } from 'vue'
import Url from './Url.vue'
const time = ref('loading...')
Expand Down
1 change: 1 addition & 0 deletions playground/vue/Null.vue
@@ -0,0 +1 @@
<template>null</template>
10 changes: 10 additions & 0 deletions playground/vue/Url.vue
@@ -0,0 +1,10 @@
<script setup>
import url from './Null.vue?url'
</script>

<template>
<h2>import with ?url</h2>
<div>
URL of Null.vue: <span class="import-with-url-query">{{ url }}</span>
</div>
</template>
8 changes: 8 additions & 0 deletions playground/vue/__tests__/vue.spec.ts
Expand Up @@ -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'
)
})
})
2 changes: 1 addition & 1 deletion playground/vue/tsconfig.json
Expand Up @@ -3,5 +3,5 @@
// esbuild transpile should ignore this
"target": "ES5"
},
"include": ["src"]
"include": ["."]
}
1 change: 1 addition & 0 deletions playground/vue/vite-env.d.ts
@@ -0,0 +1 @@
/// <reference types="vite/client" />

0 comments on commit 97d200c

Please sign in to comment.