Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Allow specifying a variables file with a cli option? #72

Closed
hgl opened this issue Feb 26, 2015 · 8 comments
Closed

Allow specifying a variables file with a cli option? #72

hgl opened this issue Feb 26, 2015 · 8 comments

Comments

@hgl
Copy link

hgl commented Feb 26, 2015

Since postcss-custom-properties accepts a variables option, I wonder if you are interested in allowing the cli to accept a json/yaml file path option, which will read its file content and pass the json object to postcss-custom-properties?

I can send a pull request if you are interested in merging.

@MoOx
Copy link
Owner

MoOx commented Feb 26, 2015

Maybe a more generic way to provides options from a config file for CLI ?

@hgl
Copy link
Author

hgl commented Feb 26, 2015

Then the variables json object should be directly embedded in the config file or only the file path?

My use case is that I need to expose some css variable values to my js scripts, and my plan is to save these values in a json file. cssnext will read it when processing css files, and my js files will require it before accessing it. That way, these values are available to both css and js.

It would be great if this json file only contains css variable values, and not other cssnext configs, because they are unless to js scripts.

If only the file path should be specified in the config file, I think we still should provide the option to CLI. The config file is then just a higher level structure.

What do you think?

@MoOx
Copy link
Owner

MoOx commented Feb 26, 2015

I don't really want to accept an option for just an option of an features. If anyone ask for this, we will end up with shitty spaghetti code.

By more generic I mean a config file that can like a .rc file

$ cssnext --config-file cssnext.json

cssnext.json

{
  "features": {
    "customProps": {
      "variables": {}
    }
  }
}

From js you can do

var cssVars = require("./cssnext.json").features.customProps.variables

If you need do that too many times, you can imagine a module

./cssvars.js

module.exports = require("./cssnext.json").features.customProps.variables

Then

var cssVars = require("./cssvars.js")

@hgl
Copy link
Author

hgl commented Feb 26, 2015

I initially didn't want to take this approach because I would eventually bundle the js files, and the bundled file was going include the whole json file, not only the variables part.

But I think your concern about supporting too many options is valid, if variables is supported as an external file, why not supporting custom media queries also for example? The config file approach is very scalable. I can still write css variables and custom media queries to their own files and generate the config file accordingly.

Will send a pull request soon.

@bloodyowl
Copy link
Contributor

@MoOx how about a cssnext.config.js that can require another module for variables?

@MoOx
Copy link
Owner

MoOx commented Feb 26, 2015

Yeah I was more thinking about that. But @hgl just want a simple file for variables. I don't see how we can make this simple & not super specific for cli interface.

I will open a new issue for a generic config file that can be used.

@hgl
Copy link
Author

hgl commented Feb 27, 2015

@bloodyowl In #74, I used something like require(configPath), so if configPath points to a module file, it should also work.

@MoOx
Copy link
Owner

MoOx commented Mar 5, 2015

Closed by 224b6b6

@MoOx MoOx closed this as completed Mar 5, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants