English | 简体中文
@vant/auto-import-resolver
is a resolver for unplugin-vue-components that enables on-demand importing of Vant components.
- Supports
Vite
,Webpack
,Rspack
,Vue CLI
,Rollup
,esbuild
, and more. - Automatically imports the corresponding CSS styles for the components.
- Supports SSR (Server-Side Rendering).
# via npm
npm i @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
# via yarn
yarn add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
# via pnpm
pnpm add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
# via Bun
bun add @vant/auto-import-resolver unplugin-vue-components unplugin-auto-import -D
// vite.config.ts
import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';
export default defineConfig({
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
});
// rollup.config.js
import AutoImport from 'unplugin-auto-import/rollup';
import Components from 'unplugin-vue-components/rollup';
import { VantResolver } from '@vant/auto-import-resolver';
export default {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
};
// webpack.config.js
import AutoImport from 'unplugin-auto-import/webpack';
import Components from 'unplugin-vue-components/webpack';
import { VantResolver } from '@vant/auto-import-resolver';
module.exports = {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
};
// rspack.config.js
import AutoImport from 'unplugin-auto-import/rspack';
import Components from 'unplugin-vue-components/rspack';
import { VantResolver } from '@vant/auto-import-resolver';
module.exports = {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
};
// vue.config.js
import AutoImport from 'unplugin-auto-import/webpack';
import Components from 'unplugin-vue-components/webpack';
import { VantResolver } from '@vant/auto-import-resolver';
module.exports = {
configureWebpack: {
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
},
};
// esbuild.config.js
import { build } from 'esbuild';
import AutoImport from 'unplugin-auto-import/esbuild';
import Components from 'unplugin-vue-components/esbuild';
import { VantResolver } from '@vant/auto-import-resolver';
build({
plugins: [
AutoImport({
resolvers: [VantResolver()],
}),
Components({
resolvers: [VantResolver()],
}),
],
});
Whether to automatically import the corresponding styles of the components.
- Type:
boolean
- Default:
true
- Example:
Components({
resolvers: [
VantResolver({
// Disable style import
importStyle: false,
}),
],
});
Specifies the type of module to be imported.
- Type:
'esm' | 'cjs'
- Default:
'esm'
- Example:
Components({
resolvers: [
VantResolver({
module: 'cjs',
}),
],
});
- Type:
boolean
- Default:
undefined
This option is deprecated. Please use the module
option to set the module type.