mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): don't return stub function from tree-shaken composables (#5786)
This commit is contained in:
parent
728a0a5ef4
commit
b045b7141b
@ -10,7 +10,7 @@ interface TreeShakePluginOptions {
|
||||
}
|
||||
|
||||
export const TreeShakePlugin = createUnplugin((options: TreeShakePluginOptions) => {
|
||||
const COMPOSABLE_RE = new RegExp(`($|\\s*)(${options.treeShake.join('|')})(?=\\()`, 'g')
|
||||
const COMPOSABLE_RE = new RegExp(`($|\\s+)(${options.treeShake.join('|')})(?=\\()`, 'gm')
|
||||
|
||||
return {
|
||||
name: 'nuxt:server-treeshake:transfrom',
|
||||
@ -35,7 +35,7 @@ export const TreeShakePlugin = createUnplugin((options: TreeShakePluginOptions)
|
||||
const s = new MagicString(code)
|
||||
const strippedCode = stripLiteral(code)
|
||||
for (const match of strippedCode.matchAll(COMPOSABLE_RE) || []) {
|
||||
s.overwrite(match.index, match.index + match[0].length, `(() => {}) || /*#__PURE__*/ false && ${match[0]}`)
|
||||
s.overwrite(match.index, match.index + match[0].length, `${match[1]} /*#__PURE__*/ false && ${match[2]}`)
|
||||
}
|
||||
|
||||
if (s.hasChanged()) {
|
||||
|
Loading…
Reference in New Issue
Block a user