Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output style JSON #253

Closed
jackmahoney opened this issue Mar 12, 2014 · 4 comments
Closed

Output style JSON #253

jackmahoney opened this issue Mar 12, 2014 · 4 comments

Comments

@jackmahoney
Copy link

Hi would it be difficult to include an output style that is JSON? The reason for this is I would like to be able to compile SASS with node-sass then iterate over it like an object in a Grunt JS plugin and use that information for some post-processing tasks.

One example would be getting SASS variables and making them available in JS. I'm happy to contribute if you could point me in the right direction.

Cheers

@bwilkins
Copy link
Contributor

Hi Jack,

The main thing standing in your way would be that node-sass is a wrapper around libsass, and libsass doesn't support this kind of functionality (to my knowledge).

This is likely to be something that you add into the package yourself, contributing it if you want.

As for where you want to start... output styles are defined at https://github.com/andrew/node-sass/blob/master/sass.js#L22-L27 , and the sass render/renderSync exports are defined at https://github.com/andrew/node-sass/blob/master/sass.js#L68-L101 . You might want to add your own "json" entry to the accepted output styles, and something in render/renderSync to do your bidding based on the outputStyle. Note that you will not want to send the "json" outputStyle to libsass.

@jackmahoney
Copy link
Author

Hmm okay, so you think I would need to contribute to libsass? I may end up just writing a simple regex pattern to extract variables instead.

The idea is just to make variables available in JS. Ie:

$breakpoint-mobile : 320px => window.sass['breakpoint-mobile']

Also thanks for getting back to me :)

@bwilkins
Copy link
Contributor

This is sounding more like something that you could/should do outside of node-sass. This may just be because I don't understand your use-case, but I don't know that many people would find a JSON output useful.

What would happen when you pass outputStyle: "json" to the render/renderSync methods? Does it completely ignore libsass and do it's own thing?

I guess the next best question is, what are you trying to achieve by doing this? Is there another, hopefully better way to do it?

@jackmahoney
Copy link
Author

I think you're right. I'll pursue an independent track. Thanks for your help anyway - it was useful. Cheers.

jamesw-minted pushed a commit to jamesw-minted/node-sass that referenced this issue May 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants