Closed icetech233 closed 2 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);
引入颜色模块:
@use "sass:color";
使用color.channel()
函数:
rgb
)。$color: #c71585;
@debug color.channel($color, "blue", $space: rgb);
--verbose
标志可以打印所有弃用警告。--quiet-deps
标志可以静默依赖项的弃用警告。--silence-deprecation
标志可以静默特定弃用警告。假设你的原始代码是这样的:
.blue-color {
color: blue($color);
}
你可以修改为:
@use "sass:color";
.blue-color {
color: color.channel($color, "blue", $space: rgb);
}
这样修改后,你的代码将兼容新的Sass颜色函数,并避免弃用警告。
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
你遇到的弃用警告是因为你正在使用的是 Dart Sass 的旧版 JavaScript API,这个旧版 API 已经在 Dart Sass 1.45.0 版本中被标记为弃用,并将在 Dart Sass 2.0.0 版本中被完全移除。
你需要迁移到新的现代 JavaScript API。以下是一些关键的迁移步骤:
编译入口点:
render
和 renderSync
方法。compile
和 compileAsync
方法用于编译文件,compileString
和 compileStringAsync
方法用于编译字符串。导入器:
canonicalize
和 load
。canonicalize
方法返回规范化的 URL,load
方法返回加载的样式表内容。自定义函数:
done
回调。捆绑器:
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'],
});
希望这些信息能帮助你顺利完成迁移!
已修复
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