4

I am trying to find an easy way to export Sass maps to a json format so they can be used in my js as well. I have found multiple libraries around but they all are doing the opposite (from what I can tell) aka using js variables in sass.

TL DR; Is there a way to export sass maps to JSON format?

Preferably in gulp as I am using this for build automation.

Found libraries:

NealVDV
  • 2,302
  • 3
  • 26
  • 51

3 Answers3

2

Hi a little late but have you tried this one? sass-export

It is in early version but it might help you.

civanm
  • 71
  • 4
0

Try this npm package - sass-json-export

It returns a JSON inside the output CSS file. You have the option to have the JSON returned inside a media query or a comment. This CSS file can be easily parsed to extract the JSON part into a separate JSON file.

Jithin Nair
  • 841
  • 9
  • 7
0

Solved it by using the node sass export module, the creator helped me solve my issue.

NealVDV
  • 2,302
  • 3
  • 26
  • 51
  • Hey did it work with non map variables for you ? I saw your conversations with the author on github and managed to run everything but variables like $spacer: 1rem are not inserted inside the json object – ihor.eth Jul 31 '20 at 02:43
  • I'm not sure, I only needed it to work with maps. Hope you find it! – NealVDV Aug 21 '20 at 08:18
  • I see. I ended up forking and tweaking another library for my needs – ihor.eth Aug 21 '20 at 13:49