Daymychen / art-design-pro

这是一个基于 Vue3、TypeScript、Vite 和 Element-Plus 精心打造的后台管理系统模板,专注于用户体验和视觉设计。
https://www.lingchen.kim/art-design-pro/docs/
MIT License
39 stars 4 forks source link

有报错,修复建议 #8

Closed icetech233 closed 2 hours ago

icetech233 commented 5 hours ago

Deprecation Warning: blue() is deprecated. Suggestion:

color.channel($color, "blue", $space: rgb)

More info: https://sass-lang.com/d/color-functions

╷ 54 │ blue($color)} │ ^^^^^^^^^^^^ ╵ node_modules\element-plus\theme-chalk\src\mixins_var.scss 54:5 set-css-color-rgb() node_modules\element-plus\theme-chalk\src\var.scss 17:5 @use node_modules\element-plus\theme-chalk\src\base.scss 1:1 @use node_modules\element-plus\theme-chalk\src\index.scss 1:1 @use src\assets\styles\element.scss 26:1 root stylesheet

icetech233 commented 5 hours ago

从你提供的错误信息来看,你正在使用的Sass代码中使用了blue()函数,但这个函数已经被弃用了。这是因为Sass为了支持CSS Color Level 4中新增的颜色空间,对颜色函数进行了重大更改。

在CSS Color Level 4之前,Sass假设所有颜色值都覆盖相同的色域(sRGB),并且可以自由地在RGB、HSL或HWB等表示法之间转换。但是,随着CSS Color Level 4的发布,它增加了对许多新颜色空间的支持,这些颜色空间具有比sRGB更宽的色域。为了支持这些新颜色空间,Sass不得不重新思考颜色函数的工作方式。

解决方案

根据Sass官方文档的建议,你应该使用color.channel()函数来代替blue()。这个函数允许你指定颜色空间,从而避免歧义。具体来说,你可以按照以下方式修改你的代码:

@use "sass:color";

$color: #c71585;
@debug color.channel($color, "blue", $space: rgb);

详细步骤

  1. 引入颜色模块

    @use "sass:color";
  2. 使用color.channel()函数

    • 第一个参数是颜色值。
    • 第二个参数是通道名称(例如:"blue")。
    • 第三个参数是颜色空间(例如:rgb)。
    $color: #c71585;
    @debug color.channel($color, "blue", $space: rgb);

过渡期

管理弃用警告

示例代码

假设你的原始代码是这样的:

.blue-color {
  color: blue($color);
}

你可以修改为:

@use "sass:color";

.blue-color {
  color: color.channel($color, "blue", $space: rgb);
}

这样修改后,你的代码将兼容新的Sass颜色函数,并避免弃用警告。

icetech233 commented 5 hours ago

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-api

icetech233 commented 5 hours ago

你遇到的弃用警告是因为你正在使用的是 Dart Sass 的旧版 JavaScript API,这个旧版 API 已经在 Dart Sass 1.45.0 版本中被标记为弃用,并将在 Dart Sass 2.0.0 版本中被完全移除。

解决方案

你需要迁移到新的现代 JavaScript API。以下是一些关键的迁移步骤:

  1. 编译入口点

    • 旧版 API 使用 renderrenderSync 方法。
    • 新版 API 使用 compilecompileAsync 方法用于编译文件,compileStringcompileStringAsync 方法用于编译字符串。
  2. 导入器

    • 旧版 API 的导入器是一个函数,返回一个对象,包含文件路径或内容。
    • 新版 API 的导入器包含两个方法:canonicalizeloadcanonicalize 方法返回规范化的 URL,load 方法返回加载的样式表内容。
  3. 自定义函数

    • 旧版 API 的自定义函数使用单独的 JS 参数和 done 回调。
    • 新版 API 的自定义函数使用单个 JS 参数,包含所有 Sass 参数,异步自定义函数返回一个 Promise。
  4. 捆绑器

    • 如果你使用的是 Webpack 或 Vite 等工具,你可能需要更新配置以使用新版 API。例如,在 Webpack 中,设置 api"modern""modern-compiler"

示例代码

假设你原来的代码是这样的:

const sass = require('node-sass');

sass.render({
  file: 'path/to/your/sass/file.scss',
  data: 'body { background-color: blue; }',
}, (err, result) => {
  if (err) {
    console.log(err);
  } else {
    console.log(result.css.toString());
  }
});

你可以将其修改为:

const sass = require('sass');

sass.compile('path/to/your/sass/file.scss').then(result => {
  console.log(result.css.toString());
}).catch(err => {
  console.error(err);
});

// 或者编译字符串
sass.compileString('body { background-color: blue; }').then(result => {
  console.log(result.css.toString());
}).catch(err => {
  console.error(err);
});

静默弃用警告

如果你暂时无法迁移到新版 API,但想静默弃用警告,可以在 Dart Sass 1.79.0 及更高版本中使用 silenceDeprecations 选项:

const sass = require('sass');

const result = sass.renderSync({
  file: 'path/to/your/sass/file.scss',
  silenceDeprecations: ['legacy-js-api'],
});

总结

希望这些信息能帮助你顺利完成迁移!

Daymychen commented 2 hours ago

已修复