构建工具采用Vite
CSS预处理器采用Sass
npm i sass -D
ElementPlus默认样式.
- //index.scss
-
- /* 只需要重写你需要的即可 */
- @forward 'element-plus/theme-chalk/src/common/var.scss' with (
- $colors: (
- 'primary': (
- // 主色
- 'base': #27ba9b,
- ),
- 'success': (
- // 成功色
- 'base': #1dc779,
- ),
- 'warning': (
- // 警告色
- 'base': #ffb302,
- ),
- 'danger': (
- // 危险色
- 'base': #e26237,
- ),
- 'error': (
- // 错误色
- 'base': #cf4444,
- ),
- )
- )
npm install unplugin-element-plus/vite
在Vite.config.js中
- import { fileURLToPath, URL } from 'node:url'
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
- //按需引入样式
- import AutoImport from 'unplugin-auto-import/vite'
- import Components from 'unplugin-vue-components/vite'
- import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
- // 导入对应包
- import ElementPlus from 'unplugin-element-plus/vite'
- export default defineConfig({
- plugins: [
- vue(),
- AutoImport({
- resolvers: [ElementPlusResolver()],
- }),
- Components({
- resolvers: [ElementPlusResolver()],
- }),
- // 按需定制主题配置
- ElementPlus({
- useSource: true,
- }),
- ],
- resolve: {
- alias: {
- '@': fileURLToPath(new URL('./src', import.meta.url))
- }
- },
- css: {
- preprocessorOptions: {
- scss: {
- // 自动导入定制化样式文件进行样式覆盖
- additionalData: `
- @use "@/styles/element/index.scss" as *;
- `,
- }
- }
- }
- })