Run PostCSS synchronously?
See original GitHub issueI am writing my own node script for development. I am facing a problem where PostCSS processes the files asynchronously and the server starts before the compilation is complete.
I know it should return a LazyResult, is there a way to not do that? This is my code:
const processCSS = () => {
const CSSFile = fs.readFileSync(path.resolve(__dirname, '../src/styles/main.css'));
postcss(postcssConfig.plugins)
.process(CSSFile, { from: 'src/styles/main.css', to: '.tmp/styles/main.css' })
.then(result => {
fs.writeFileSync('.tmp/styles/main.css', result.css, () => true);
logInfo('CSS', 'steelblue', 'Processed successfully');
if ( result.map ) {
fs.writeFileSync('.tmp/styles/main.css', result.map, () => true);
}
})
.catch(err => {
});
}
processCSS();
I tried switching to async/await
without success. I’ve seen this old issue and I still have no clue what should be done.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Use autoprefixer synchronously - css - Stack Overflow
PostCSS has an API for synchronously getting the results of Processor#process ( process().css , aliased as toString() ), which will work as long...
Read more >PostCSS API
Processes input CSS through synchronous and asynchronous plugins and calls onFinally on any error or when all plugins will finish work.
Read more >postcss/postcss - Gitter
I used postcss6 with postcss-nested, postcss-import, postcss-cssnext and autoprefixer in babel6 plugin earler in synchronous mode.
Read more >postcss-modules-sync - npm
Start using postcss-modules-sync in your project by running `npm i postcss-modules-sync`. There are 27 other projects in the npm registry ...
Read more >Learn how to power-up your CSS with PostCSS - YouTube
If you're going to use the preset-env, I'd strongly recommend adding the PostCSS Language Support plugin to VS Code, so that it recognizes ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sergeysova if you do not want to use async plugins, you can call PostCSS sync API:
I found the problem,
Those plugins I use don’t offer sync mode:
Thank you, that sounds like a reasonable solution