@ftvs/auto-import-resolver
v0.0.2
Published
ftvs auto import resolver based on unplugin-vue-components
Downloads
2
Readme
Vant Auto Import Resolver
English | 简体中文
@ftvs/auto-import-resolver
是 unplugin-vue-components 的一个解析器,用于实现 Vant 按需引入。
特性
- 支持
Vite
,Webpack
,Rspack
,Vue CLI
,Rollup
,esbuild
等 - 支持自动引入组件对应的 CSS 样式
- 支持 SSR(服务端渲染)
安装
# via npm
npm i @ftvs/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
# via yarn
yarn add @ftvs/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
# via pnpm
pnpm add @ftvs/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
# via Bun
bun add @ftvs/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
使用
Vite
// vite.config.ts
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@ftvs/auto-import-resolver';
export default defineConfig({
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
});
Rollup
// rollup.config.js
import AutoImport from 'unplugin-auto-import/rollup';
import Components from 'unplugin-vue-components/rollup';
import { VantResolver } from '@ftvs/auto-import-resolver';
export default {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
};
Webpack
// webpack.config.js
import AutoImport from 'unplugin-auto-import/webpack';
import Components from 'unplugin-vue-components/webpack';
import { VantResolver } from '@ftvs/auto-import-resolver';
module.exports = {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
};
Rspack
// rspack.config.js
import AutoImport from 'unplugin-auto-import/rspack';
import Components from 'unplugin-vue-components/rspack';
import { VantResolver } from '@ftvs/auto-import-resolver';
module.exports = {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
};
Vue CLI
// vue.config.js
import AutoImport from 'unplugin-auto-import/webpack';
import Components from 'unplugin-vue-components/webpack';
import { VantResolver } from '@ftvs/auto-import-resolver';
module.exports = {
configureWebpack: {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
},
};
esbuild
// esbuild.config.js
import { build } from 'esbuild';
import AutoImport from 'unplugin-auto-import/esbuild';
import Components from 'unplugin-vue-components/esbuild';
import { VantResolver } from '@ftvs/auto-import-resolver';
build({
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
});
选项
importStyle
是否自动引用组件对应的样式。
- Type:
boolean
- Default:
true
- Example:
Components({
resolvers: [
VantResolver({
// 禁用样式引用
importStyle: false,
}),
],
});
module
设置引用的模块类型。
- Type:
'esm' | 'cjs'
- Default:
'esm'
- Example:
Components({
resolvers: [
VantResolver({
module: 'cjs',
}),
],
});
ssr
- Type:
boolean
- Default:
undefined
此选项已废弃,请使用 module
选项来设置模块类型。