Skip to content

Commit d44408e

Browse files
committedNov 18, 2024
fix(nuxt): handle empty plugin files

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

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

+12-4
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)
Please sign in to comment.