Vite處理css postcss import variable less
阿新 • • 發佈:2022-06-06
支援css3 variables
src/styles/index.css
/* css3 variable */
:root{
--main-font-color: blue
}
#app{
font-size: 20px;
color: var(--main-font-color);
}
main.js
import { createApp } from 'vue'
import App from './App.vue'
import './styles/index.css'
createApp(App).mount('#app')
支援postcss
/* css3 variable */ :root{ --main-font-color: blue } #app{ font-size: 20px; @console.log hello postcss; color: var(--main-font-color); }
"dependencies": {
"@postcss-plugins/console": "^0.2.4",
}
postcss.config.js
module.exports = {
plugins:[require('@postcss-plugins/console')]
}
css import
@import url(./other.css);
div{}
css-modules
定義 test.module.css
.moduleClass{
color: lightgreen;
}
使用
import { defineComponent } from "vue"; import classes from "@styles/test.module.css" export default defineComponent({ setup() { return () => <div className={`${classes.moduleClass}`}>vite app jsx</div> } })
css-processor scss/less
安裝依賴
yarn add less
test.less
@bgColor:red;
.lessBox{
color: @bgColor;
}
App.jsx
import { defineComponent } from "vue"; import classes from "@styles/test.module.css" import '@styles/test.less' export default defineComponent({ setup() { return () => <div className={`${classes.moduleClass}`}>vite app jsx <div className="lessBox">less box</div></div> } })