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

postcss option doesn't work #478

Closed
CYLee2020 opened this issue Dec 8, 2022 · 3 comments · Fixed by #513
Closed

postcss option doesn't work #478

CYLee2020 opened this issue Dec 8, 2022 · 3 comments · Fixed by #513
Labels
bug Something isn't working

Comments

@CYLee2020
Copy link

I want to add a feature "logical-properties-and-values" like:

module.exports = {
    style: {
        postcss: {
            env: {
                stage: 3,
                features: {
                    'nesting-rules': true,
                    'logical-properties-and-values': { "dir": "ltr" }
                }
            }
        },
    }
};

i want to do this,but it doesn't work;

inset:0;
//becomes
top:0;left:0;right:0;bottom:0;

verison

"react-scripts": "5.0.1",
"@craco/craco": "^7.0.0"
@CYLee2020 CYLee2020 added the bug Something isn't working label Dec 8, 2022
@larsmunkholm
Copy link

larsmunkholm commented Mar 10, 2023

I've had a similar issue where craco was completely ignoring any configurations I made to postcss.
I tried following the craco documentation and recipes, but nothing worked.

Then I thought, that maybe I could customize the postcss config through webpack using craco's getLoader - but that didn't work either. So I gave up.

But after a good night's sleep I came up with the following:

const { getLoaders, loaderByName } = require("@craco/craco");

module.exports = {
    webpack: {
        configure: (webpackConfig) => {
            const { hasFoundAny: postCssHasFoundAny, matches: postcssMatches } = getLoaders(
                webpackConfig,
                loaderByName("postcss-loader")
            );

            if (postCssHasFoundAny) {
                postcssMatches[postcssMatches.length - 1].loader.options.postcssOptions.config =
                    path.join(__dirname, "./postcss.config.js");
            }

            return webpackConfig;
        },
    },
};

This makes craco use postcss.config.js.

You could probably do something like this, if you don't want to use a config file:

postcssMatches[postcssMatches.length - 1].loader.options.postcssOptions.env = {
    ...postcssMatches[postcssMatches.length - 1].loader.options.postcssOptions.env,
    stage: 3,
    features: {
        'nesting-rules': true,
        'logical-properties-and-values': { "dir": "ltr" }
    }
};

@vlad-elagin
Copy link

@CYLee2020 @larsmunkholm same for me, but CRACO doesn't ignore style.postcss.loaderOptions from craco.config.js. I could add postcss plugins via this API, not sure if it'll work for env tho. Example in #506

@dilanx
Copy link
Owner

dilanx commented May 26, 2023

This issue is linked to #513 and will be closed once that's merged but please leave a comment if it isn't resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants