Named export for Vue SFC.
npm i -D unplugin-vue-named-export
Vite
// vite.config.ts
import VueNamedExport from 'unplugin-vue-named-export/vite'
export default defineConfig({
plugins: [
VueNamedExport({
/* options */
}),
],
})
Rollup
// rollup.config.js
import VueNamedExport from 'unplugin-vue-named-export/rollup'
export default {
plugins: [
VueNamedExport({
/* options */
}),
],
}
esbuild
// esbuild.config.js
import { build } from 'esbuild'
build({
plugins: [
require('unplugin-vue-named-export/esbuild')({
/* options */
}),
],
})
Webpack
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-vue-named-export/webpack')({
/* options */
}),
],
}
Use pascal case named exports in Vue SFC.
import { MyFooter } from './my_footer.vue'
import { MyCard } from './my-card.vue'
import { MyComponent } from './MyComponent.vue'
type Options = {
include?: string | RegExp | (string | RegExp)[]
exclude?: string | RegExp | (string | RegExp)[]
/**
* Convert filename to export name
* @default pascalCaseFn
*/
resolveName?: (id: string) => string | Promise<string>
/**
* Whether to keep default export
* @default false
*/
removeDefault?: boolean
}
For Vue Language Tools (Volar) < 2.0, please use unplugin-vue-named-export@0.3.0
Support only pascal case named export for Volar.
// tsconfig.json
{
// ...
"vueCompilerOptions": {
"plugins": ["unplugin-vue-named-export/volar"],
"namedExport": {
// defaults to false
"removeDefault": false,
},
},
}