From e727bb4192ee5e838f8416b798b97bc1ffd183fb Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 11 Feb 2022 08:59:52 +0000 Subject: [PATCH] fix(nuxt3): re-enable tree-shaking `definePageMeta` (#3180) --- packages/nuxt3/src/pages/macros.ts | 7 +++++-- packages/nuxt3/src/pages/runtime/composables.ts | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/nuxt3/src/pages/macros.ts b/packages/nuxt3/src/pages/macros.ts index be80f549e8..7b5b950c25 100644 --- a/packages/nuxt3/src/pages/macros.ts +++ b/packages/nuxt3/src/pages/macros.ts @@ -13,9 +13,10 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi enforce: 'post', transformInclude (id) { const { search, pathname } = parseURL(id) - return pathname.endsWith('.vue') || parseQuery(search).macro + return pathname.endsWith('.vue') || !!parseQuery(search).macro }, transform (code, id) { + const originalCode = code const { search } = parseURL(id) // Tree-shake out any runtime references to the macro. @@ -27,7 +28,9 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi } } - if (!parseQuery(search).macro) { return } + if (!parseQuery(search).macro) { + return originalCode === code ? undefined : code + } // [webpack] Re-export any imports from script blocks in the components // with workaround for vue-loader bug: https://github.com/vuejs/vue-loader/pull/1911 diff --git a/packages/nuxt3/src/pages/runtime/composables.ts b/packages/nuxt3/src/pages/runtime/composables.ts index 52b0f4df5e..8d9a204a86 100644 --- a/packages/nuxt3/src/pages/runtime/composables.ts +++ b/packages/nuxt3/src/pages/runtime/composables.ts @@ -25,7 +25,7 @@ declare module 'vue-router' { const warnRuntimeUsage = (method: string) => console.warn( `${method}() is a compiler-hint helper that is only usable inside ` + - '