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

fix(webpack): don't parse styles for composable keys #7333

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/vite/src/plugins/composable-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { walk } from 'estree-walker'
import MagicString from 'magic-string'
import { hash } from 'ohash'
import type { CallExpression } from 'estree'
import { parseURL } from 'ufo'
import { parseQuery, parseURL } from 'ufo'

export interface ComposableKeysOptions {
sourcemap: boolean
Expand All @@ -22,8 +22,8 @@ export const composableKeysPlugin = createUnplugin((options: ComposableKeysOptio
name: 'nuxt:composable-keys',
enforce: 'post',
transform (code, id) {
const { pathname } = parseURL(decodeURIComponent(pathToFileURL(id).href))
if (!pathname.match(/\.(m?[jt]sx?|vue)/)) { return }
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
if (!pathname.match(/\.(m?[jt]sx?|vue)/) || parseQuery(search).type === 'style') { return }
if (!KEYED_FUNCTIONS_RE.test(code)) { return }
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || []
const s = new MagicString(code)
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/basic/pages/keyed-composables.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ const { data: useLazyFetchTest2 } = await useLocalLazyFetch()
{{ useLazyFetchTest1 === useLazyFetchTest2 }}
</div>
</template>

<style scoped>
body {
background-color: #000;
color: #fff;
}
</style>