packages/vant-cli/docs/config.md
Vant CLI uses Rsbuild to build the documentation site. You can create an Rsbuild configuration file in the same directory as vant.config.mjs. The contents of the file will be automatically read by Vant CLI.
// rsbuild.config.mjs or rsbuild.config.ts
export default {
plugins: [
// Configure Rsbuild plugins
],
dev: {
// Options related to local development
},
html: {
// Options related to HTML generation
},
// Other options
};
Please refer to Configure Rsbuild for more information.
Vant Cli uses Vite to build component library code. You can create a Vite configuration file in the same directory as vant.config.mjs. In this file, you can add any Vite configuration.
Please refer to Vite Configuration to learn more.
vant.config.mjs includes bundle and documentation site config. Please create this file and place it in your project root directory. Here is a basic example:
export default {
// component library name
name: 'demo-ui',
// bundle config
build: {
site: {
publicPath: '/demo-ui/',
},
},
// documentation site config
site: {
// title
title: 'Demo UI',
// logo
logo: 'https://fastly.jsdelivr.net/npm/@vant/assets/logo.png',
// description
description: '示例组件库',
// left nav
nav: [
{
title: 'example',
items: [
{
path: 'home',
title: 'home',
},
],
},
{
title: 'basic components',
items: [
{
path: 'my-button',
title: 'MyButton',
},
],
},
],
},
};
string''Component library name. kebab-case recommended.
string'style/base.less'Global style file path. Support absolute path and relative path both.
Note: relative path is calculated based on src.
module.exports = {
build: {
css: {
base: 'style/global.scss',
},
},
};
string'less'CSS preprocessor config, support less and sass. Use less by default.
module.exports = {
build: {
css: {
preprocessor: 'sass',
},
},
};
boolean'false'Whether to remove the source style files after build.
module.exports = {
build: {
css: {
removeSourceFile: true,
},
},
};
string/Equivalent to vite build.outDir.
Generally, documentation site will be deployed to subpath of domain. For example: https://my.github.io/demo-ui/, publicPath should be /demo-ui/.
module.exports = {
build: {
site: {
publicPath: '/demo-ui/',
},
},
};
stringsrcmodule.exports = {
build: {
srcDir: 'myDir',
},
};
booleanfalseShould export components by Named Export.
When set to false, export default from 'xxx' will be used to export module.
When set to true, export * from 'xxx' will be used to export all modules and type definition.
(config: InlineConfig): InlineConfig | undefinedundefinedCustom vite config, requires @vant/cli>= 4.0.0.
module.exports = {
build: {
configureVite(config) {
config.server.port = 3000;
return config;
},
},
};
If you need to configure some vite plugins, please create a vite.config.ts file in the same directory of vant.config.mjs, in which you can add any vite configuration (this feature requires @vant/cli 5.1.0).
'npm' | 'yarn' | 'pnpm' | 'bun'yarnnpm package manager.
BundleOptions[]Specify the format of the bundled output.
The type of BundleOptions:
type BundleOption = {
// Whether to minify code (Tips: es format output can't be minified by vite)
minify?: boolean;
// Formats, can be set to 'es' | 'cjs' | 'umd' | 'iife'
formats: LibraryFormats[];
// Dependencies to external (Vue is externaled by default)
external?: string[];
};
Default value:
const DEFAULT_OPTIONS: BundleOption[] = [
{
minify: false,
formats: ['umd'],
},
{
minify: true,
formats: ['umd'],
},
{
minify: false,
formats: ['es', 'cjs'],
external: allDependencies,
},
];
string''Documentation site title.
string''Documentation site logo.
string''Documentation site description.
object[]undefinedDocumentation site left nav. Each item of nav means a navigation group.
module.exports = {
site: {
nav: [
{
// group title
title: 'Development Guide',
// nav items
items: [
{
// nav router
path: 'home',
// nav title
title: 'title',
// should hide phone emulator(false by default)
hideSimulator: true,
},
],
},
],
},
};
object[]undefinedDocumentation site muti-version config.
module.exports = {
site: {
versions: [
{
label: 'v1',
link: '/v1/',
},
],
},
};
objectundefinedDocumentation site baidu analysis config. The script of Baidu Statistic will be automatically loaded when build documentation website.
module.exports = {
site: {
baiduAnalytics: {
// 打开百度统计 ->『管理』->『代码获取』
// find the followed URL: "https://hm.baidu.com/hm.js?xxxxx"
// add `xxxxx` in the seed
seed: 'xxxxx',
},
},
};
booleanfalseShould hide phone emulator, false by default.
stringCustomize iframe URL.
Record<string, string>undefinedCustomize HTML meta tag, key means name, value means content.
stringundefinedInsert a custom HTML content in the <head> tag.
booleanfalseWhether to enable vConsole debugging in dev, usually used for mobile debugging.
PostCSS can be configured through the postcss.config.js file in the root directory.
PostCSS default config:
module.exports = {
plugins: {
autoprefixer: {},
},
};
Add browserslist field to package.json file is recommended. It's used by autoprefixer to determine the version of target browser, ensuring compatibility of compiled code.
You can add the following config for mobile:
{
"browserslist": ["Chrome >= 51", "iOS >= 10"]
}