feat(CLI): support for configuring Rsbuild (#12809)

This commit is contained in:
neverland
2024-04-20 16:30:55 +08:00
committed by GitHub
parent 6744198fd8
commit ec9cb2be36
3 changed files with 68 additions and 70 deletions

View File

@@ -1,6 +1,8 @@
# Config
- [Config](#----)
- [rsbuild.config.mjs](#rsbuildconfigmjs)
- [vite.config.mjs](#viteconfigmjs)
- [vant.config.mjs](#vantconfigmjs)
- [name](#name)
- [build.css.base](#buildcssbase)
@@ -8,7 +10,6 @@
- [build.site.publicPath](#buildsitepublicpath)
- [build.srcDir](#buildsrcdir)
- [build.namedExport](#buildnamedexport)
- [build.configureVite](#buildconfigurevite)
- [build.packageManager](#buildpackagemanager)
- [site.title](#sitetitle)
- [site.logo](#sitelogo)
@@ -24,6 +25,34 @@
- [Default Config](#-----1)
- [browserslist](#browserslist)
## rsbuild.config.mjs
Vant CLI uses [Rsbuild](https://github.com/web-infra-dev/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.
```js
// 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](https://rsbuild.dev/guide/basic/configure-rsbuild) for more information.
## vite.config.mjs
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](https://vitejs.dev/config/) to learn more.
## vant.config.mjs
`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:
@@ -192,28 +221,6 @@ module.exports = {
};
```
```js
module.exports = {
build: {
configureVite(config) {
const { BUILD_TARGET } = process.env;
if (BUILD_TARGET === 'package') {
// component library bundle config
}
if (BUILD_TARGET === 'site') {
// documentation site bundle config
}
return config;
},
},
};
```
Note that you are not allowed to import vite plugins in `vant.config.mjs`, because the file will be bundled into the website code.
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).
### build.packageManager