如何在 scss 全局声明中使用 hsl 而不是 rgb javascript api

问题描述

这就是我的 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 并返回颜色,就像您现在所做的一样。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...