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

Scripts: Add support for postcss.config.js #22732

Closed
ocean90 opened this issue May 29, 2020 · 2 comments · Fixed by #22735
Closed

Scripts: Add support for postcss.config.js #22732

ocean90 opened this issue May 29, 2020 · 2 comments · Fixed by #22735
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Build Tooling Issues or PRs related to build tooling [Type] Enhancement A suggestion for improvement.

Comments

@ocean90
Copy link
Member

ocean90 commented May 29, 2020

Description

This is a follow-up for #21730 and the comments from #21730 (comment)

Currently the @wordpress/postcss-config gets imported right into the webpack.config.js file. How can we make it as easy as possible to extend or override this config? It would be awesome if we could allow for just adding a postcss.config.js file to be root of the project and the script then referencing that one instead of the one from the @wordpress/postcss-config package.

I wasn't aware that postcss.config.js is a thing :) It looks like it's standardized: https://github.com/michael-ciniawsky/postcss-load-config. I'm more than happy to add support for it in a follow-up PR. It will be very similar to how we handle all other configs (Babel, ESLint, etc.) 👍

I was playing around with the new version and really like it. postcss.config.js was the only thing that's missing.

Here's an example of such a postcss.config.js:

module.exports = ( ctx ) => {
	const config = {
		plugins: {
			'postcss-import': {} ,
			'postcss-mixins': {} ,
			'postcss-nested': {} ,
			'postcss-preset-env': {
				stage: 0,
				preserve: false, // Omit pre-polyfilled CSS.
				features: {
					'nesting-rules': false, /* Uses postcss-nesting which doesn't behave like Sass. */
				},
				autoprefixer: {
					grid: true,
				},
			} ,
			'postcss-hexrgba': {} ,
			'css-mqpacker': {
				sort: true,
			} ,
		}
	};

	if ( 'development' === ctx.env ) {
		config.map = true;
	} else {
		config.map = false;
		config.plugins['cssnano'] = {
			safe: true,
		}
	}

	return config;
};

@gziolo I'm assuming you haven't played with that yet? Happy to give it a try.

@ocean90 ocean90 added [Type] Enhancement A suggestion for improvement. [Type] Build Tooling Issues or PRs related to build tooling [Tool] WP Scripts /packages/scripts labels May 29, 2020
@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label May 29, 2020
@gziolo
Copy link
Member

gziolo commented May 29, 2020

@ocean90, thanks for converting those comments into an issue, much appreciated. The idea aligns very much with all other configs we provide with defaults, e.g.:

// Provide a fallback configuration if there's not
// one explicitly available in the project.
...( ! hasBabelConfig() && {
babelrc: false,
configFile: false,
presets: [
require.resolve(
'@wordpress/babel-preset-default'
),
],
} ),

Feel free to work on it, I'm happy to help with review and testing 👍

@codetot
Copy link

codetot commented Jun 11, 2021

I found an error with compiled postcss source. #22735

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Build Tooling Issues or PRs related to build tooling [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants