Created
February 17, 2022 12:02
-
-
Save joneff/dc1d63909c8190485dc6f229710a9a71 to your computer and use it in GitHub Desktop.
sass-embedded issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const dartSass = require('sass'); | |
const dartEmbedded = require('sass-embedded'); | |
const dartJson = path.resolve('./dist/dart.json'); | |
const embeddedJson = path.resolve('./dist/embedded.json'); | |
const srcFile = path.resolve('./scss/resolve-vars.scss'); | |
function resolveVars(compiler, src, dest ) { | |
let content = {}; | |
compiler.compile( src, { | |
functions: { | |
'resolve-var($key, $type, $value)': (args) => { | |
const _key = args[0].toString(); | |
const _type = args[1].toString(); | |
const _val = args[2].toString(); | |
console.log( _key, _type, _val ); | |
content[_key] = { | |
type: _type, | |
value: _val | |
}; | |
return new compiler.SassString(''); | |
} | |
}, | |
logger: compiler.Logger.silent | |
}); | |
fs.writeFileSync( dest, JSON.stringify( content, null, 4 ) ); | |
} | |
function resolveDart() { | |
resolveVars( dartSass, srcFile, dartJson ); | |
} | |
resolveDart(); | |
function resolveEmbedded() { | |
resolveVars( dartEmbedded, srcFile, embeddedJson ); | |
} | |
resolveEmbedded(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@use "sass:meta"; | |
@use "vars.scss"; | |
$_vars: meta.module-variables("vars"); | |
body { | |
@each $key, $val in $_vars { | |
var: resolve-var( unquote($key), meta.type-of( $val ), $val ); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$var-a: 3; | |
// $var-b: calc( 4px + 3em ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment