mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 01:15:58 +00:00
fix(nuxt3): only treeshake macro exports when building (#2809)
This commit is contained in:
parent
7f62ed1e32
commit
95d8205cc3
@ -4,6 +4,7 @@ import { findStaticImports, findExports } from 'mlly'
|
||||
|
||||
export interface TransformMacroPluginOptions {
|
||||
macros: Record<string, string>
|
||||
dev?: boolean
|
||||
}
|
||||
|
||||
export const TransformMacroPlugin = createUnplugin((options: TransformMacroPluginOptions) => {
|
||||
@ -42,7 +43,7 @@ export const TransformMacroPlugin = createUnplugin((options: TransformMacroPlugi
|
||||
if (match.specifier && match._type === 'named') {
|
||||
// [webpack] Export named exports rather than the default (component)
|
||||
return code.replace(match.code, `export {${Object.values(options.macros).join(', ')}} from "${match.specifier}"`)
|
||||
} else {
|
||||
} else if (!options.dev) {
|
||||
// ensure we tree-shake any _other_ default exports out of the macro script
|
||||
code = code.replace(match.code, '/*#__PURE__*/ false &&')
|
||||
code += '\nexport default {}'
|
||||
|
@ -47,6 +47,7 @@ export default defineNuxtModule({
|
||||
|
||||
// Extract macros from pages
|
||||
const macroOptions: TransformMacroPluginOptions = {
|
||||
dev: nuxt.options.dev,
|
||||
macros: {
|
||||
definePageMeta: 'meta'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user