Skip to content

Run PostCSS synchronously? #1328

@ahmadalfy

Description

@ahmadalfy

I 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions