问题描述
这就是我的 next.config.js 的样子
// next.config.js
const env = require('./site.config').env;
const Colour = require('sass').types.Color;
const {r,g,b} = require('./site.config').customProperties;
const withBundleAnalyzer = require('@next/bundle-analyzer')({enabled: !!process.env.ANALYZE});
const config = {
env: {
...env,},sassOptions: {
functions: {
'primaryOpacityColour()': function(){
return new Colour(r,b)
// here I want to return Colour in hsl form
},};
module.exports = withBundleAnalyzer(config);
我无法以 hsl 形式返回 Color,有人能帮我解决这个问题吗?
解决方法
根据 https://github.com/sass/sass/issues/2988,您不能使用 javascript api 执行此操作。 dart-sass 在 dart api 中有它,但在 javascript api 中没有。
您最好的选择是从 hsl 转换为 rgb 并返回颜色,就像您现在所做的一样。