Skip to content

Commit d44408e

Browse files
committed
fix(nuxt): handle empty plugin files
1 parent da7370d commit d44408e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

packages/nuxt/src/core/plugins/plugin-metadata.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,26 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => {
125125
const plugin = nuxt.apps.default?.plugins.find(p => p.src === id)
126126
if (!plugin) { return }
127127

128-
const s = new MagicString(code)
128+
if (!code.trim()) {
129+
logger.warn(`Plugin \`${plugin.src}\` has no content.`)
130+
131+
return {
132+
code: 'export default () => {}',
133+
map: { mappings: '' },
134+
}
135+
}
136+
129137
const exports = findExports(code)
130138
const defaultExport = exports.find(e => e.type === 'default' || e.name === 'default')
131139
if (!defaultExport) {
132140
logger.warn(`Plugin \`${plugin.src}\` has no default export and will be ignored at build time. Add \`export default defineNuxtPlugin(() => {})\` to your plugin.`)
133-
s.overwrite(0, code.length, 'export default () => {}')
134141
return {
135-
code: s.toString(),
136-
map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : null,
142+
code: 'export default () => {}',
143+
map: { mappings: '' },
137144
}
138145
}
139146

147+
const s = new MagicString(code)
140148
let wrapped = false
141149
const wrapperNames = new Set(['defineNuxtPlugin', 'definePayloadPlugin'])
142150

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy