Search code examples
node.jssassnode-sassdart-sass

How to parse/get variables from scss/sass via dart-sass/node-sass


Have a question. Maybe you can help me.

Is it possible to get a variables info from rendering the scss file via dart-sass.

For example, I have a style.scss:

$md: 768px;

.class {
  min-height: 0;
}

And running this script:

const path = require('path')
const sass = require('sass')

const res = sass.renderSync({file: path.join(__dirname, 'style.scss')})

console.log(res.css.toString())

I've got the result: .class { min-height: 0; }. I've checked the documentation and didn't find anything related to the render process and ger the scss file content rather than css file content as a string.

Thanks a lot. Have a nice day.


Solution

  • You should use 'fs' module and regexp or postcsc-scss to deal with the variables.

    Link: https://github.com/sass/dart-sass/issues/1231