-
-
Notifications
You must be signed in to change notification settings - Fork 244
Closed
Labels
Description
This is pretty simple to reproduce with version 3.0.0.
Create a test.js file:
var a = "class1";And a test.css file:
.class1 {
color: blue;
}
.class2 {
color:red;
}
.class3 {
color: green;
}Then run purgecss --content test.js --css test.css --safelist class2 (as documented):
$ npx purgecss --content test.js --css test.css --safelist class2 [14:28:56]
[{"css":".class1 {\n color: blue;\n}\n\n.class2 {\n color:red;\n}\n\n.class3 {\n color: green;\n}\n","file":"test.css"}]
(node:15305) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'length' of undefined
at U.shouldKeepSelector (/Users/dbruhn/repos/temp/node_modules/purgecss/lib/purgecss.js:1:9032)The output is created despite the error, but all classes are preserved. (class3 should have been purged.)
Purging works fine without the whitelist:
$ npx purgecss --content test.js --css test.css [14:28:59]
[{"css":".class1 {\n color: blue;\n}\n","file":"test.css"}]The code is throwing because this.options.safelist.greedy is undefined:
purgecss/packages/purgecss/src/index.ts
Line 711 in beb4a59
| if (this.options.safelist.greedy.length > 0) { |
lorenzschmid, alanquigley-toast and sormiston