postcss / postcss-simple-vars

PostCSS plugin for Sass-like variables

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multiple js variable files?

pengx17 opened this issue · comments

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') ];
        }
    })
]

Use ES6 descturctors:

{
    ...require('./config/colors'),
    ...require('./config/layout')
}

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

What error do you have?

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

variables: {
    ...require('./config/colors'),
    ...require('./config/layout')
}

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