postcss / postcss-simple-vars

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

Multiple js variable files? #41

Closed pengx17 closed 8 years ago

pengx17 commented 8 years ago

E.g., if I have two JS files containing two sets of variables:

// config/colors.js

module.exports = {
    blue: '#056ef0'
}

// config/layout.js

module.exports = {
    wide: '1000px'
}

Can I inject the two set of variables?

postcss([
    vars({
        variables: function () {
            return [ require('./config/colors'), require('./config/layout') ];
        }
    })
]
ai commented 8 years ago

Use ES6 descturctors:

{
    ...require('./config/colors'),
    ...require('./config/layout')
}
mariomurrent-softwaresolutions commented 7 years ago

How would that look like in the example above? I can't get it to run with multiple files

ai commented 7 years ago

What error do you have?

mariomurrent-softwaresolutions commented 7 years ago

See my example: require('postcss-simple-vars')({ variables: function variables() { return require('../src/file1') }, unknown: function unknown(node, name, result) { node.warn(result, 'Unknown variable ' + name) } }),

How exactly do I insert a second file after return require('../src/file1') so that e.g file1 and file2 are used

ai commented 7 years ago
variables: {
    ...require('./config/colors'),
    ...require('./config/layout')
}
mariomurrent-softwaresolutions commented 7 years ago

Yeah, sorry - I missed a require in the second file. Thank you for you quick response and help :)