mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
2.4 KiB
2.4 KiB
Vant Auto Import Resolver
@vant/auto-import-resolver 用于 Vant 按需引入,基于 unplugin-vue-components 的解析器
特性
-
支持
Vite
,Webpack
,Rspack
,Vue CLI
,Rollup
,esbuild
等, 基于 unplugin-vue-components -
支持自动引入 css 样式
VantResolver()
默认 -
支持自动引入 less 样式
VantResolver({ importStyle: false | 'less' })
提示:Vant 4.0 以上 npm 包内移除了 less 文件
-
支持 ssr
VantResolver({ ssr: true })
安装
# via npm
npm i @vant/auto-import-resolver unplugin-vue-components -D
# via yarn
yarn add @vant/auto-import-resolver unplugin-vue-components -D
# via pnpm
pnpm add @vant/auto-import-resolver unplugin-vue-components -D
# via Bun
bun add @vant/auto-import-resolver unplugin-vue-components -D
Vite
// vite.config.ts
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';
export default defineConfig({
plugins: [
Components({
resolvers: [VantResolver()],
}),
],
});
Rollup
// rollup.config.js
import Components from 'unplugin-vue-components/rollup';
import { VantResolver } from '@vant/auto-import-resolver';
export default {
plugins: [
Components({
resolvers: [VantResolver()],
}),
],
};
Webpack
// webpack.config.js
import Components from 'unplugin-vue-components/webpack';
import { VantResolver } from '@vant/auto-import-resolver';
module.exports = {
plugins: [
Components({
resolvers: [VantResolver()],
}),
],
};
Vue CLI
// vue.config.js
import Components from 'unplugin-vue-components/webpack';
import { VantResolver } from '@vant/auto-import-resolver';
module.exports = {
configureWebpack: {
plugins: [
Components({
resolvers: [VantResolver()],
}),
],
},
};
esbuild
// esbuild.config.js
import { build } from 'esbuild';
import Components from 'unplugin-vue-components/esbuild';
import { VantResolver } from '@vant/auto-import-resolver';
build({
plugins: [
Components({
resolvers: [VantResolver()],
}),
],
});