mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 00:52:01 +00:00
fix(nuxt): handle empty plugin files
This commit is contained in:
parent
da7370dfda
commit
d44408e87b
@ -125,18 +125,26 @@ export const RemovePluginMetadataPlugin = (nuxt: Nuxt) => createUnplugin(() => {
|
|||||||
const plugin = nuxt.apps.default?.plugins.find(p => p.src === id)
|
const plugin = nuxt.apps.default?.plugins.find(p => p.src === id)
|
||||||
if (!plugin) { return }
|
if (!plugin) { return }
|
||||||
|
|
||||||
const s = new MagicString(code)
|
if (!code.trim()) {
|
||||||
|
logger.warn(`Plugin \`${plugin.src}\` has no content.`)
|
||||||
|
|
||||||
|
return {
|
||||||
|
code: 'export default () => {}',
|
||||||
|
map: { mappings: '' },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const exports = findExports(code)
|
const exports = findExports(code)
|
||||||
const defaultExport = exports.find(e => e.type === 'default' || e.name === 'default')
|
const defaultExport = exports.find(e => e.type === 'default' || e.name === 'default')
|
||||||
if (!defaultExport) {
|
if (!defaultExport) {
|
||||||
logger.warn(`Plugin \`${plugin.src}\` has no default export and will be ignored at build time. Add \`export default defineNuxtPlugin(() => {})\` to your plugin.`)
|
logger.warn(`Plugin \`${plugin.src}\` has no default export and will be ignored at build time. Add \`export default defineNuxtPlugin(() => {})\` to your plugin.`)
|
||||||
s.overwrite(0, code.length, 'export default () => {}')
|
|
||||||
return {
|
return {
|
||||||
code: s.toString(),
|
code: 'export default () => {}',
|
||||||
map: nuxt.options.sourcemap.client || nuxt.options.sourcemap.server ? s.generateMap({ hires: true }) : null,
|
map: { mappings: '' },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const s = new MagicString(code)
|
||||||
let wrapped = false
|
let wrapped = false
|
||||||
const wrapperNames = new Set(['defineNuxtPlugin', 'definePayloadPlugin'])
|
const wrapperNames = new Set(['defineNuxtPlugin', 'definePayloadPlugin'])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user