fix(nuxt): only tree-shake composables on their own lines (#5850)

This commit is contained in:
Daniel Roe 2022-07-12 11:55:12 +01:00 committed by GitHub
parent 8685bfa9e9
commit 2d70507d1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,17 +10,17 @@ interface TreeShakePluginOptions {
}
export const TreeShakePlugin = createUnplugin((options: TreeShakePluginOptions) => {
const COMPOSABLE_RE = new RegExp(`($|\\s+)(${options.treeShake.join('|')})(?=\\()`, 'gm')
const COMPOSABLE_RE = new RegExp(`($\\s+)(${options.treeShake.join('|')})(?=\\()`, 'gm')
return {
name: 'nuxt:server-treeshake:transfrom',
enforce: 'post',
transformInclude (id) {
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href))
const { type, macro } = parseQuery(search)
const { type } = parseQuery(search)
// vue files
if (pathname.endsWith('.vue') && (type === 'script' || macro || !search)) {
if (pathname.endsWith('.vue') && (type === 'script' || !search)) {
return true
}