postcss / postcss-simple-vars

PostCSS plugin for Sass-like variables
MIT License
415 stars 36 forks source link

Expose variables as json #38

Closed duncanbeevers closed 8 years ago

duncanbeevers commented 8 years ago

I have a use-case where rather than trying to store css variables in JavaScript, I would like to store them as css and have postcss-simple-var export encountered variables.

ai commented 8 years ago

Maybe I can add a callback

ai commented 8 years ago

Is this API is OK?

require('postcss-simple-vars')({
    onVariables: function (file, vars) {
        // vars will contains variables in file
    }
})
ai commented 8 years ago

There is a temporary solution:

let vars = { };
let plugin = require('postcss-simple-vars')({
  variables: vars
});

postcss([plugin]).process(css);
// other files

vars // => { one: '1px', other variables from CSS }
duncanbeevers commented 8 years ago

I think a callback is more appropriate. In my proof-of-concept implementation, onVariables is exactly the callback I used. I'll bake up a PR.