docs: add vite theme guide (#8656)

This commit is contained in:
neverland 2021-05-04 22:07:47 +08:00 committed by GitHub
parent a5fedbb6ac
commit 52fb7628f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 86 additions and 6 deletions

View File

@ -133,13 +133,13 @@ module.exports = {
options: {
lessOptions: {
modifyVars: {
// overide with less vars
// override with less vars
'text-color': '#111',
'border-color': '#eee'
'border-color': '#eee',
// or override with less file
'hack': `true; @import "your-less-file-path.less";`
hack: `true; @import "your-less-file-path.less";`,
},
}
},
},
},
],
@ -158,7 +158,7 @@ module.exports = {
less: {
lessOptions: {
modifyVars: {
// overide with less vars
// override with less vars
'text-color': '#111',
'border-color': '#eee',
// or override with less file
@ -170,3 +170,42 @@ module.exports = {
},
};
```
### Vite
Add the following config in `vite.config.js`.
```js
// vite.config.js
import vue from '@vitejs/plugin-vue';
import styleImport from 'vite-plugin-style-import';
export default {
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
modifyVars: {
'text-color': '#111',
'border-color': '#eee',
},
},
},
},
resolve: {
alias: [{ find: /^~/, replacement: '' }],
},
plugins: [
vue(),
styleImport({
libs: [
{
libraryName: 'vant',
esModule: true,
resolveStyle: (name) => `vant/es/${name}/style/less`,
},
],
}),
],
};
```

View File

@ -93,7 +93,7 @@ Vant 使用了 [Less](http://lesscss.org/) 对样式进行预处理,并内置
#### 按需引入样式(推荐)
在 babel.config.js 中配置按需引入样式源文件,注意 babel6 不支持按需引入样式,请手动引入样式。
在 babel.config.js 中配置按需引入样式源文件,注意 babel 6 不支持按需引入样式,请手动引入样式。
```js
module.exports = {
@ -178,3 +178,44 @@ module.exports = {
},
};
```
### Vite 项目
如果是 vite 项目,可以跳过以上步骤,直接在 `vite.config.js` 中添加如下配置即可。
```js
// vite.config.js
import vue from '@vitejs/plugin-vue';
import styleImport from 'vite-plugin-style-import';
export default {
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
// 覆盖样式变量
modifyVars: {
'text-color': '#111',
'border-color': '#eee',
},
},
},
},
resolve: {
alias: [{ find: /^~/, replacement: '' }],
},
plugins: [
vue(),
// 按需引入样式源文件
styleImport({
libs: [
{
libraryName: 'vant',
esModule: true,
resolveStyle: (name) => `vant/es/${name}/style/less`,
},
],
}),
],
};
```