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

[Bug]: regex not recognized when using PostCSS json config (postcss.config.json) #1258

Open
1 task done
gkorakas-eli opened this issue Jun 5, 2024 · 0 comments
Open
1 task done
Labels

Comments

@gkorakas-eli
Copy link

gkorakas-eli commented Jun 5, 2024

Describe the bug

According to the following commit, Angular supports PostCSS configuration only via json config files:

angular/angular-cli@7c522aa

I am trying to purge CSS code like Bootstrap's using the following config (postcss.config.json) and Angular cli gives an error at PurgeCSS.isSelectorSafelistedDeep

t.test is not a function
node_modules/purgecss/lib/purgecss.js:1:9639

To Reproduce

I have created an angular environment to describe the issue but the same goes for other frameworks in case the PostCSS config is JSON.

https://stackblitz.com/edit/angular-postcss-purgecss?file=src%2Fmain.ts

  1. Create a new angular app by running ng new my-app
  2. Add Bootstrap as a dependency
  3. Create a new postcss.config.json with the content:
{
    "plugins": {
        "@fullhuman/postcss-purgecss": {
            "content": [
                "src/**/*.html"
            ],
            "safelist": {
                "standard": [
                    "primary$",
                    "^mt-\\d",
                    "btn$",
                    "invalid-feedback",
                    "fade",
                    "show",
                    "collapsing",
                    "anticon$"
                ],
                "deep": [
                    "^form-\\w[a-z-]+",
                    "^modal-.*",
                    "^offcanvas-.*",
                    "^row-cols-.*",
                    "^btn-.*",
                    "^col-.*",
                    "^ant-.*",
                    "^nz-.*",
                    "^cdk-.*"
                ],
                "greedy": [],
                "keyframes": [],
                "variables": []
            },
            "skippedContentGlobs": []
        }
    }
}
  1. Run npm run build

Expected Behavior

JSON config to be parsed correctly so the regex patterns inside safelist.deep and safelist.greedy are taken into consideration without giving error.

Environment

Angular version 17.2 and above or another framework with postcss.config.json

Add any other context about the problem here

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@gkorakas-eli gkorakas-eli changed the title [Bug]: regex not recognised when using PostCSS json config (postcss.config.json) [Bug]: regex not recognized when using PostCSS json config (postcss.config.json) Jun 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant