当前位置: 首页 > news >正文

【已解决】element-plus配置主题色后,sass兼容问题。set-color-mix-level() is...in Dart Sass 3

项目:vue3+vite

  "scripts": {"dev": "vite","build": "vite build","preview": "vite preview"},"dependencies": {"@element-plus/icons-vue": "^2.3.1","animate.css": "^4.1.1","axios": "^1.7.7","element-plus": "^2.8.6","pinia": "^2.2.4","pinia-plugin-persistedstate": "^4.1.2","sass": "^1.80.6","swiper": "^11.1.14","vite-plugin-vue-devtools": "^7.5.4","vue": "^3.5.10","vue-i18n": "^10.0.0","vue-router": "^4.4.5"}

按照官方配置后,本地启动服务 npm run dev 和构建 npm run build,都会出现警告和报错

https://element-plus.org/zh-CN/guide/theming.html
在这里插入图片描述
src\styles\element\index.scss
在这里插入图片描述
vite.config.js

....
import ElementPlus from "unplugin-element-plus/vite";
...
export default function ({ mode }) {.return defineConfig({plugins: [
...ElementPlus({useSource: true,}),...],css: {preprocessorOptions: {scss: {additionalData: `@use "@/styles/theme.scss" as *;@use "@/styles/element/index.scss" as *;`,},},},...});
}

警告信息
除了警告,还有报错
在这里插入图片描述

> npm run dev> ...
> viteVITE v5.4.9  ready in 523 ms➜  Local:   http://localhost:3000/➜  Network: http://192.168.18.119:3000/➜  press h + enter to show help
Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-apiDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-apiDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-apiDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-apiDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-apiDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-api10:36:25 [vite] Pre-transform error: [sass] Can't find stylesheet to import.╷
1 │ @use "~/styles/element/index.scss" as *;@use 'mixins/mixins' as *;│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^╵node_modules\element-plus\theme-chalk\src\message.scss 1:1  root stylesheet
10:36:25 [vite] Pre-transform error: [sass] Can't find stylesheet to import.╷
1 │ @use "~/styles/element/index.scss" as *;@use 'sass:map';│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^╵node_modules\element-plus\theme-chalk\src\message-box.scss 1:1  root stylesheet
10:36:25 [vite] Pre-transform error: [sass] Can't find stylesheet to import.

解决方案:
官方公告!!!
https://github.com/element-plus/element-plus/issues/15834

将 sass版本变更为 1.79.0

npm i sass@1.79.3

之后发现,比之前好点了,但是还是会有警告,不过没有报错了。
在这里插入图片描述
继续解决警告问题!
https://github.com/element-plus/element-plus/issues/18732
在这里插入图片描述
解决!不警告和报错了!
在这里插入图片描述

总结:

警告和报错的原因:

这些警告是由于 Dart Sass 版本升级后出现的弃用警告,主要有两个方面的问题:

全局内置 mix 函数弃用: Dart Sass 建议用 color.mix 替代 mix 函数,以避免弃用问题。Element Plus 的主题文件 var.scss 中使用了 mix,在未来的 Dart Sass 3.0.0 中可能会不兼容。

全局变量声明的弃用: Sass 即将不再允许使用 !global 在局部作用域中声明新变量。解决方法是声明变量 $B 在全局作用域中初始化(例如 $B: null;),然后在局部作用域中更新它。

Deprecation Warning: Global built-in functions are deprecated and will be removed in Dart Sass 3.0.0.
Use color.mix instead.More info and automated migrator: https://sass-lang.com/d/import╷
63 │ ┌           mix(
64 │ │             $mix-color,
65 │ │             map.get($colors, $type, 'base'),
66 │ │             math.percentage(math.div($number, 10))
67 │ │           ),│ └───────────^╵node_modules\element-plus\theme-chalk\src\common\var.scss 63:11  set-color-mix-level()node_modules\element-plus\theme-chalk\src\common\var.scss 87:5   @forwardsrc\styles\element\index.scss 3:1                                @usenode_modules\element-plus\theme-chalk\src\base.scss 3:11         root stylesheet
旧版Sass API的警告:

提示正在使用旧的JS API,建议升级到最新版本的Dart Sass以兼容新的API。

Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-apiDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.More info: https://sass-lang.com/d/legacy-js-apiDeprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.

解决方案

  1. 将 sass版本变更为 1.79.0
npm i sass@1.79.3

2.vite.config.js
添加配置:
silenceDeprecations:[‘legacy-js-api’]

    css: {preprocessorOptions: {scss: {additionalData: `@use "@/styles/theme.scss" as *;@use "@/styles/element/index.scss" as *;`,silenceDeprecations:['legacy-js-api']},},},
http://www.lryc.cn/news/476151.html

相关文章:

  • JavaWeb——Web入门(4/9)-HTTP协议:请求协议(请求行、请求头、请求体、演示 )
  • 软考:数据库考点总结
  • Flash的语音ic型号有哪些?
  • 10天进阶webpack---(1)为什么要有webpack
  • HTML CSS
  • 第03章 MySQL的简单使用命令
  • 【C++动态规划】2435. 矩阵中和能被 K 整除的路径|1951
  • 三、Kafka集群
  • [数据结构]堆
  • UDP-鼠李糖合成酶基因的克隆与鉴定-文献精读76
  • 【H2O2|全栈】JS进阶知识(四)Ajax
  • Spring IOC的工作流程
  • 从新手到专家:7款电脑平面设计软件评测
  • 【C++】如何让C++字符串更快、C++的小字符串优化
  • C++《list》
  • strongswan中METHOD定义
  • Rive 动画框架竟然支持响应式布局,全平台动画框架开启全新 UI 交互能力
  • MQ的详细大全知识点
  • AI图像相似性搜索对比:VIT, CLIP, DINO-v2, BLIP-2
  • 【tomcat系列漏洞利用】
  • 前端学习-盒子模型(十八)
  • 【C++】类和对象(十二):实现日期类
  • 文章解读与仿真程序复现思路——电网技术EI\CSCD\北大核心《提升系统频率支撑能力的“车-氢”柔性可控负荷协同构网控制》
  • 异或的性质
  • 新一代Webshell管理器
  • 「iOS」——知乎日报一二周总结
  • windows C#-匿名类型
  • CryptoHack 简介
  • transformControls THREE.Object3D.add: object not an instance of THREE.Object3D.
  • 游戏开发与游戏运营:哪个更难?