@chengdx/default-export-resolver
v0.11.6
Published
Help to generate default export for `unplugin-vue-components`
Downloads
13
Maintainers
Readme
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 }