npm i sass-loader
npm i sass (vite+vue3仅需安装sass,内置loader)
<style lang="scss">
$color: red;
.aaa{
background-color: $color;
width: 100px;
height: 100px;
}
</style>
- vite+vue3全局引入scss变量
// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [vue()],
// start
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "./src/assets/css/common" as *;'
}
}
}
// stop
})
网友评论