Describe the bug
When I try to run my build I'm getting an error that the config file can't be found.
To Reproduce
Steps to reproduce the behavior:
"purgecss": "purgecss -c purgecss.config.js -o src"module.exports = {
content: ['src/index.js'],
css: ['src/tailwind.css']
}
yarn run buildError: Error loading the config fileCannot find module '/C:\GitHub\repo/purgecss.config.jsExpected behavior
Build should happen with css purged
Desktop (please complete the following information):
Additional context
This was raised on StackOverflow as well: https://stackoverflow.com/questions/51569213/purgecss-cli-c-cannot-find-module-purgecss-config-js/52277041
thanks for reporting this, it looks like a bug on windows, in this path /C:\GitHub\repo/purgecss.config.js the last slash should be a backslash and i'm not sure if that first slash before C: should be there
Agreed, that's what I commented on the StackOverflow bug too. Hopefully it's not too bad to fix.
Ill have to first setup a VM with windows to test this but a possible workaround would be to just not use a config file and use purgecss programmatically. Create a purge_my_css.js file with something like this:
const Purgecss = require('purgecss')
const fs = require('fs')
const path = require('path')
const outputDir = path.resolve(__dirname, 'dist')
const purgecss = new Purgecss({
content: ['src/*.html'],
css: ['src/*.css']
})
const result = purgecss.purge()
result.forEach(out => {
const filePath = out.file.split('/')
fs.writeFileSync(`${outputDir}/${filePath[filePath.length - 1]}`, out.css, 'utf-8')
})
console.log('done')
then just run it with node purge_my_css.js
I've fixed the issue on my end by simply replacing
var t = path.resolve(process.cwd(), pathConfig);
with
var t = path.join(process.cwd(), pathConfig);
I'm assuming since process.cwd() returns a fixed path, using join over resolve is a non-issue, but I'm not in the position to make PR's or tests at the moment.
Maybe someone else can research if this change would cause any issues?
The fix from @alexqhj worked in my windows machine.
I finally got this to work by putting a symlink to the node_modules directory (named "node_modules") in each directory where I was running purgecss from.
This problem still exists under windows.

i just changed it directly in the purgecss file

and apprently the developpers know the problem
Most helpful comment
Ill have to first setup a VM with windows to test this but a possible workaround would be to just not use a config file and use purgecss programmatically. Create a
purge_my_css.jsfile with something like this:then just run it with
node purge_my_css.js