Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

Commit 3a71f1d

Browse files
committed
fix(webpack): don't parse styles for composable keys
1 parent 6b3a1a4 commit 3a71f1d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/vite/src/plugins/composable-keys.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { walk } from 'estree-walker'
55
import MagicString from 'magic-string'
66
import { hash } from 'ohash'
77
import type { CallExpression } from 'estree'
8-
import { parseURL } from 'ufo'
8+
import { parseQuery, parseURL } from 'ufo'
99

1010
export interface ComposableKeysOptions {
1111
sourcemap: boolean
@@ -22,8 +22,8 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
2222
name: 'nuxt:composable-keys',
2323
enforce: 'post',
2424
transform (code, id) {
25-
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href))
26-
if (!pathname.match(/\.(m?[jt]sx?|vue)/)) { return }
25+
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
26+
if (!pathname.match(/\.(m?[jt]sx?|vue)/) || parseQuery(search).type === 'style') { return }
2727
if (!KEYED_FUNCTIONS_RE.test(code)) { return }
2828
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || []
2929
const s = new MagicString(code)

test/fixtures/basic/pages/keyed-composables.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,10 @@ const { data: useLazyFetchTest2 } = await useLocalLazyFetch()
4343
{{ useLazyFetchTest1 === useLazyFetchTest2 }}
4444
</div>
4545
</template>
46+
47+
<style scoped>
48+
body {
49+
background-color: #000;
50+
color: #fff;
51+
}
52+
</style>

0 commit comments

Comments
 (0)