Skip to content

[Bug]: PurgeCSS CLI not working with config file #1327

@timjuedemann

Description

@timjuedemann

Describe the bug

While I still feel like I am the one doing something wrong here, I feel like I have exhausted all possible error sources on my end:

I am trying to run PurgeCSS via the CLI using the following config file:

// purgecss.config.js

console.log("Using purgecss.config.js");

module.exports = {
    content: ["index.html"],
    css: ["style.css"],
};

The directory structure of my project directory is as follows:

index.html
node_modules/
package-lock.json
package.json
purgecss.config.js
style.css

When I run PurgeCSS with the following command without the config file it works as expected:

purgecss --content index.html --css style.css --output style.purged.css

However, when I try to run it with the config file, I only get the output from the console.log but my CSS isn’t being processed:

purgecss --config ./purgecss.config.js --output style.purged.css

I assume there’s something wrong with my config file but I can’t figure out what exactly.

To Reproduce

  1. Run purgecss --content index.html --css style.css --output style.purged.css
  2. File style.purged.css is created
  3. Delete style.purged.css
  4. Run purgecss --config ./purgecss.config.js --output style.purged.css
  5. Using purgecss.config.js logged to console but style.purged.css is not being created

purgecss-testing.zip

Expected Behavior

I would expect running PurgeCSS using the config file to give me the same result as running it without, i.e. create a new file style.purged.css in my project directory containing the purged CSS. I need to be able to run PurgeCSS with a config file because I rely on being able to define a custom extractor.

Environment

macOS 15.3
purgecss 7.0.2
node 20.11.1

Add any other context about the problem here

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions