mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
docs: add vite theme guide (#8656)
This commit is contained in:
parent
a5fedbb6ac
commit
52fb7628f2
@ -133,13 +133,13 @@ module.exports = {
|
|||||||
options: {
|
options: {
|
||||||
lessOptions: {
|
lessOptions: {
|
||||||
modifyVars: {
|
modifyVars: {
|
||||||
// overide with less vars
|
// override with less vars
|
||||||
'text-color': '#111',
|
'text-color': '#111',
|
||||||
'border-color': '#eee'
|
'border-color': '#eee',
|
||||||
// or override with less file
|
// 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: {
|
less: {
|
||||||
lessOptions: {
|
lessOptions: {
|
||||||
modifyVars: {
|
modifyVars: {
|
||||||
// overide with less vars
|
// override with less vars
|
||||||
'text-color': '#111',
|
'text-color': '#111',
|
||||||
'border-color': '#eee',
|
'border-color': '#eee',
|
||||||
// or override with less file
|
// 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`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
@ -93,7 +93,7 @@ Vant 使用了 [Less](http://lesscss.org/) 对样式进行预处理,并内置
|
|||||||
|
|
||||||
#### 按需引入样式(推荐)
|
#### 按需引入样式(推荐)
|
||||||
|
|
||||||
在 babel.config.js 中配置按需引入样式源文件,注意 babel6 不支持按需引入样式,请手动引入样式。
|
在 babel.config.js 中配置按需引入样式源文件,注意 babel 6 不支持按需引入样式,请手动引入样式。
|
||||||
|
|
||||||
```js
|
```js
|
||||||
module.exports = {
|
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`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user