先安装 vite 构建工具

# 先安装 vite 构建工具
npm install -g create-vite-app

创建项目:

# 下面两个命令都可以
create-vite-app vue3-demo
cva vue3-demo

按照官网修改主题色

官网
我选择的是通过 scss 修改主题色
例子参照:element-plus-vite-starter

创建 index.scss 文件

# ./styles/element/index.scss
$--colors: (
"primary": (
"base": #ee4444,
),
"success": (
"base": #21ba45,
),
"warning": (
"base": #f2711c,
),
"danger": (
"base": #db2828,
),
"error": (
"base": #db2828,
),
"info": (
"base": #42b8dd,
),
);

@forward "element-plus/theme-chalk/src/common/var.scss" with
(
// do not use same name, it will override.
$colors: $--colors,
$button-padding-horizontal: ("default": 50px)
);

vue.config.ts 代码如下

import path from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// https://vitejs.dev/config/
export default defineConfig({
resolve: {
alias: {
"~/": `${path.resolve(__dirname, "src")}/`,
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "~/styles/element/index.scss" as *;`,
},
},
},
plugins: [
vue(),
Components({
resolvers: [
ElementPlusResolver({
importStyle: "sass",
}),
],
}),
],
});