postcss: JS API example not working
Hi there. I have a problem… I cant understand how readme example is supposed to work:
var postcss = require('postcss');
postcss([ require('autoprefixer'), require('cssnano') ])
.process(css, { from: 'src/app.css', to: 'app.css' })
.then(function (result) {
fs.writeFileSync('app.css', result.css);
if ( result.map ) fs.writeFileSync('app.css.map', result.map);
});
What is css? In the doc you write It is a String with input CSS…
but if I have to read my input file and place it as a string to css argument, what is options.from then?
Also, why I should write app.css file in promise then? What is options.to then?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 20 (14 by maintainers)
@Diokuz
@Diokuz I thought about file system shortcut. But it is unnecessary in most of cases:
gulp-postcssgets file content via Gulp API.postcss-loadergets file content via webpack API.fs.In result there is no good reason to some
postcss().readAndWrite()shortcut. Anyway most of PostCSS runners will get file content by other way.I made JS API example in docs more clear: 2820c76
Thanks for your questions