neverland cc9aced041
docs(auto-import-resolver): add doc for importStyle option (#12382)
* docs(auto-import-resolver): add doc for importStyle option

* docs: upd
2023-10-22 21:30:40 +08:00

2.7 KiB

Vant Auto Import Resolver

English | 简体中文

@vant/auto-import-resolver is a resolver for unplugin-vue-components that enables on-demand importing of Vant components.

Features

  • Supports Vite, Webpack, Rspack, Vue CLI, Rollup, esbuild, and more.
  • Automatically imports the corresponding CSS styles for the components.
  • Supports SSR (Server-Side Rendering).

Installation

# 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

Usage

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()],
    }),
  ],
};

Rspack

// rspack.config.js
import Components from 'unplugin-vue-components/rspack';
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()],
    }),
  ],
});

Options

importStyle

Whether to automatically import the corresponding styles of the components.

  • Type: boolean
  • Default: true
  • Example:
Components({
  resolvers: [
    VantResolver({
      // Disable style import
      importStyle: false,
    }),
  ],
});