-
-
Notifications
You must be signed in to change notification settings - Fork 245
Unable to Exclude Folders From Content Globs #620
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
Comments
Thanks for giving this more exposure. Some additional references: https://github.com/isaacs/node-glob/blob/master/README.md#comments-and-negation says
The new
At first glance, it looks like the ignore option would have go to into } catch (err) {
filesNames = glob.sync(globfile, { nodir: true });
} |
Yea, I forked the repo and implemented the option (I called it “skiplist” because I felt that was more descriptive). I think(?) I got it right, but I had some trouble building everything. Probably because I’m doing something dumb with the mono repo. I’ll push my changes to my fork and then post it here so you can take a look. I implemented the option only for purgeCSS core and postcss-purgecss because I don’t use any of the other bindings. Should be pretty easy to extend all of them though. |
Thanks for taking a look at this @bdkjones.
and you can then run the test, and build:
|
@bdkjones Reading the "Note" at master...bdkjones:master#diff-ec064e2ecde8584821d98c416e636e9a3889037faa41387bc725986b877a403eR99
… I wonder if the name Something like |
I've successfully got the I suspect this is because the Here's what I have: master...bdkjones:master |
Actually, I think it might be that I’m just really bad at Regex. I can’t seem to make glob’s
Unanchored patterns such as I looked at the test cases |
Turns out I'm only 50% stupid. It was an issue with |
PR submitted: #638 |
FYI for those looking for a workaround until #638 (thanks bdkjones) is usable in your codebase, you could do something like this: This will remove all paths that include the /styleguide/ folder. const contentGlobWithoutStyleguide = () => {
// (1) Recreate the file list the same way PostCSS does it
const glob = require("glob")
return [
'./app/**/*.html.erb',
'./app/**/*.html.slim',
'./app/helpers/**/*.rb',
'./app/javascript/**/*.js',
'./app/javascript/**/*.jsx',
'./config/locales/**/*.yml',
'./config/locales/**/*.json',
].flatMap((pattern) => glob.sync(pattern, { nodir: true }))
.filter((path) => !path.includes('/styleguides/')) // (2) Ignore Styleguide in PurgeCSS
}
environment.plugins.push(
require('@fullhuman/postcss-purgecss')({
content: contentGlobWithoutStyleguide(),
safelist: …,
defaultExtractor: …
})
) To test this, you can console.log the outpout of the defaultExtractor. For example like this: postCssDebugOutputForDevelopmentEnv = true // default false
…
defaultExtractor: content => {
let match = content.match(/…/gi) || []
if (postCssDebugOutputForDevelopmentEnv === true) {
console.log(match)
}
return match
} |
Closing because this feature has landed on master. Thanks guys! |
Describe the bug
I'm filing this as a bug because the top results on Google for "purgeCSS skip folder" link to outdated advice from the PurgeCSS team. Specifically: #158 (comment)
You advise folks to use this syntax to skip a certain folder:
The trouble is that your
glob
dependency removed support for!
as a negation operator in version 6.0. You currently use version 7 ofglob
. The!
operator is supported only inglob
5.x and below.The way to skip folders in
glob
6.x+ is to use theirignore
option, which PurgeCSS does not currently expose.To Reproduce
Simply try to use the
!
operator to negate a content glob; it will fail and PurgeCSS will remove rules that it SHOULD keep because it's not scanning files appropriately.Expected behavior
PurgeCSS should allow users to skip certain folders, such as
node_modules
—especially because these folders can contain thousands of subfolders and having PurgeCSS scan all of them needlessly makes you look slow and bad.Screenshots
N/A
Environment (please complete the following information):
Additional Context
There are other people asking for ways to exclude folders:
#551
The text was updated successfully, but these errors were encountered: