Skip to content

unplugin/unplugin-vue-named-export

Repository files navigation

unplugin-vue-named-export npm

Unit Test

Named export for Vue SFC.

Installation

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 */
    }),
  ],
}


Usage

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'

Options

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
}

Vue Language Tools (Volar)

For Vue Language Tools (Volar) < 2.0, please use [email protected]

Support only pascal case named export for Volar.

// tsconfig.json
{
  // ...
  "vueCompilerOptions": {
    "plugins": ["unplugin-vue-named-export/volar"],

    "namedExport": {
      // defaults to false
      "removeDefault": false,
    },
  },
}

Sponsors

License

MIT License © 2023-PRESENT 三咲智子