nuxt / vite

⚡ Vite Experience with Nuxt 2

Home Page:https://vite.nuxtjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

default export modification for plugins does not work with rollup / siroc builds.

ayalon opened this issue · comments

In Rollup recently an important change was made to solve issues with named export and default exports.
See rollup/rollup#4182

The most important change is that default exports are now always rendered as
export {binding as default};
instead of
export default binding;

If you use siroc (which uses Rollup) to build your nuxt plugin, you will get the following export in your plugin:
export { myplugin as default };

This is fine and correct.

Unfortunatly the defaultExportPlugin() nuxt vite scrables these files:

/src/plugins/default-export.ts

const hasDefaultExport = (code: string = '') => code.includes('export default')
const addDefaultExport = (code: string = '') => code + '\n\n' + 'export default () => {}'

The plugin only searches for export default and will add another export default () => {} at the end resulting in
Duplicate export 'default' error.

The defaultExportPlugin() export plugin should also search for default exports in a different notation like that:

const hasNamedDefaultExport = (code: string = '') => code.includes('as default')

The search string is not very prone to false positives but it shows the issue.

Hi @ayalon. Would you please provide a minimal reproduction?