-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[gatsby-plugin-postcss] breaks css minification in production #7729
Comments
Could you create a small reproduction site for this? Not sure what's going on. Does mini-css-extract-plugin minify by default for us? Perhaps you want this? https://github.com/leodido/postcss-clean |
No problem! Here's a reproduction site: https://github.com/ooloth/gatsby-postcss-test. It's just the default Gatsby v2 starter with If you comment out Yes, I believe Thanks for the link to |
@mdreizin any idea what's happening? |
I will take a look as soon as I reach home. |
Thanks! |
@ooloth @KyleAMathews I could reproduce this issue, but I need more time to fix it. |
@mdreizin sounds great — this isn't an urgent bug so can take a bit of time. If you do get blocked on fixing, please write up your guess at the cause so someone else could pick it up if they'd like. |
@KyleAMathews @ooloth We could achieve minification by using the recommendation from https://github.com/webpack-contrib/mini-css-extract-plugin#minimizing-for-production. For instance, you can use the following snippet:
exports.onCreateWebpackConfig = ({
actions,
stage
}) => {
const isProduction = stage !== 'develop';
if (isProduction) {
actions.setWebpackConfig({
devtool: false,
optimization: {
minimizer: [new OptimizeCssAssetsPlugin({})]
}
});
}
}; |
@ooloth how do we know Gatsby is minimizing CSS by default? |
(thanks for the research work @mdreizin) |
@KyleAMathews I'm inferring that Gatsby is minimizing the CSS by default from that fact that when you install the default starter and build it, the CSS inlined in the head is minified. It only stops being minified after you activate Hope that adds up! |
I think this should be resolved with #7934 which adds OptimizeCssAssetsPlugin. |
This seems to be fixed (using |
Agreed! It's fixed in Thanks everyone! |
Description
Adding
gatsby-plugin-postcss
to a Gatsby v2 site seems to cause CSS to no longer be minified in production.Steps to reproduce
Install the default Gatsby v2 starter, run
gatsby build && gatsby serve
and note that the production CSS is minified. (So far, so good.)Now, run
npm i gatsby-plugin-postcss precss autoprefixer
and addgatsby-plugin-postcss
togatsby-config
.Then, add a
postcss.config.js
file to the project root:Finally, run
gatsby build && gatsby serve
again.Expected result
Production CSS should still be minified after adding
gatsby-plugin-postcss
.Actual result
Production CSS is no longer minified.
Environment
The text was updated successfully, but these errors were encountered: