@chengdx/default-export-resolver
TypeScript icon, indicating that this package has built-in type declarations

0.11.6 • Public • Published

defaultExportResolver

Help to generate default export for unplugin-vue-components and unplugin-auto-import

unplugin-vue-components

// in vite.config.ts
import AutoImportComponents from 'unplugin-vue-components/vite'
import { defaultExportResolver } from '@chengdx/default-export-resolver'

export default defineConfig({
  plugins: [
    AutoImportComponents({
      dts: true,
      resolvers: [
        defaultExportResolver([
          { name: 'VChart', from: 'vue-echarts' },
        ]),
      ],
    }),
  ],
})

Then in the components.d.ts, a global component VChart will be generated.

// generated by unplugin-vue-components
// We suggest you to commit this file into source control
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'
export {}
declare module '@vue/runtime-core' {
  export interface GlobalComponents {
    VChart: typeof import('vue-echarts')['default']
  }
}

Now you can use VChart in your template without import it.

<template>
  <v-chart />
</template>

unplugin-auto-import

// in vite.config.ts
import AutoImport from 'unplugin-auto-import'
import { defaultExportResolver } from '@chengdx/default-export-resolver'

export default defineConfig({
  plugins: [
    AutoImportComponents({
      dts: true,
      resolvers: [
        defaultExportResolver([
          { name: 'defu', from: 'defu' },
        ]),
      ],
    }),
  ],
})

Then in the auto-import.d.ts, a global const defu will be generated.

// Generated by 'unplugin-auto-import'
export {}
declare global {
  const defu: typeof import('defu')['default']
}

Now you can use defu without import it.

const a = {
  b: 1
}

defu(a, { b: 0, c: -1 }) // { b: 1, c: -1 }

License

MIT License © 2022 Cheng-DX

Package Sidebar

Install

npm i @chengdx/default-export-resolver

Weekly Downloads

3

Version

0.11.6

License

MIT

Unpacked Size

5.2 kB

Total Files

6

Last publish

Collaborators

  • chengdx