Skip to content

using custom sass functions not working #24

Open
@quackes

Description

@quackes

Sass offers the api to register custom functions to use in sass stylesheets (https://sass-lang.com/documentation/js-api#functions)

These do not work due to the fact that stencil-sass comes with a packed version of dart-sass

Steps to reproduce

stencil.config.ts

import { Config } from '@stencil/core';
import {sass} from "@stencil/sass";
import {types} from "sass";

export const config: Config = {
  namespace: 'my-components',
  globalStyle: 'src/global/style.scss',
  plugins: [
    sass({
      functions: {
        'my-function($param)': function(param, done) {
      
           // do something fancy with param....
          return new types.String(param));
        }
      }
    })
  ]
};

src/global/style.scss

:root {
  --myvar:  my-function('my-param')
}

when I run the build the following error occurs

[ ERROR ]  sass error:src/global/style.scss:
           'my-param' must be a Sass value type.

Cause

The error occurs because dart-sass checks the type with instanceof, and the called constructor in the custom function implementation is not the same as the constructor checked in the bundled dart-sass code in stencil-sass

I "solve" the error reexporting the dart-sass object in stencil-sass and using the types from that module.
Thats not a viable workaround, more a proof of the error cause.

Suggestions

1

I don't know, why dart-sass is bundled with stencil-sass, but one solution would be to skip the bundling and load it as dependency instead of devDependency

2

Reexport the dart-sass instance in order enable the use dart-sass api outside of stencil-sass
However, this would limit the ability to use 3rd-party modules that use dart-sass

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions