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

Usage with postcss-cli? #23

Closed
nwmcsween opened this issue Feb 20, 2017 · 9 comments
Closed

Usage with postcss-cli? #23

nwmcsween opened this issue Feb 20, 2017 · 9 comments

Comments

@nwmcsween
Copy link

As per the title how can one use postcss-js with postcss-cli? Can you pass options for plugins before postcss-js?

@ai
Copy link
Member

ai commented Feb 20, 2017

@RyanZim I think we need special support for --parser postcss-js, because we need to require() file instead of reading it by fs.

What do you think?

@RyanZim
Copy link

RyanZim commented Feb 20, 2017

@ai Sorry, I'm not real familiar with postcss-js; I'm not getting why you would want to use this with the CLI. Would this be to require a CSS-in-JS file and convert it to CSS?

@ai
Copy link
Member

ai commented Feb 20, 2017

@RyanZim yeap. Input file is:

module.exports = {
  a: {
    color: 'red'
  }
}

On postcss-cli --parser postcss-js ./style.js output should be:

a {
  color: red
}

@RyanZim
Copy link

RyanZim commented Feb 20, 2017

OK, I see your point; what about when someone wants to convert CSS to JS?

postcss --stringifier postcss-js input.css -o myCSS.js

I'm not saying we should support this, just saying I can see someone asking for this sometime.

@ai
Copy link
Member

ai commented Feb 20, 2017

Good question. It will be cool to support it, but I am not sure, that users will use it :D. So up to you:

  1. Do not implement it and show warning.
  2. Stringify it by "module.exports = " + JSON.stringify(js, 4).

@RyanZim
Copy link

RyanZim commented Feb 20, 2017

I don't really want to support the stringifier that way; if postcss-js exposed a stringify function though, it would work with postcss-cli out of the box.

Either way, I'd be willing to special-case --parser postcss-js; but I want v3.0.0 shipped first. Perhaps v3.1? If you don't mind, open an issue at postcss-cli so I don't forget about this. Thanks!

@ai
Copy link
Member

ai commented Feb 20, 2017

@RyanZim sure. could you create a issue to track process?

@michael-ciniawsky
Copy link

Parser

postcss style.js -p postcss-js
if (path.extname(file) === '.js') {
  return Promise.resolve(require('file'))
    .then((content) => css(content))
}

Stringifier

postcss style.css -t postcss-js -o style.js
postcss style.css -t postcss-js --ext .js
if (path.extname(output) === '.js' || argv.ext === '.js') {
  fs.outputFile(options.to, `module.exports = ${JSON.stringify(result.css, 2)}`)
}

@ai
Copy link
Member

ai commented Feb 20, 2017

@RyanZim changes are small =^_^=

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

4 participants