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

Fix interaction with other plugins #647

Merged
merged 3 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.prefixed-used-class {
color: black;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.used-class {
color: black;
}

.unused-class {
color: black;
}

.another-one-not-found {
color: black;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>

<body>

<div class="prefixed-used-class"></div>
</body>

</html>
27 changes: 27 additions & 0 deletions packages/postcss-purgecss/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,31 @@ describe("Purgecss postcss plugin", () => {
done();
});
});

it(`lets other plugins transform selectors before purging`, async () => {
const input = fs
.readFileSync(`${__dirname}/fixtures/src/other-plugins/other-plugins.css`)
.toString();
const expected = fs
.readFileSync(`${__dirname}/fixtures/expected/other-plugins.css`)
.toString();
const result = await postcss([
{
postcssPlugin: "postcss-test-prefixer",
Rule(rule) {
if (rule.selector.startsWith(".")) {
rule.selector = ".prefixed-" + rule.selector.slice(1);
}
},
},
purgeCSSPlugin({
content: [`${__dirname}/fixtures/src/other-plugins/other-plugins.html`],
fontFace: true,
keyframes: true,
}),
]).process(input, { from: undefined });

expect(result.css).toBe(expected);
expect(result.warnings().length).toBe(0);
});
});
2 changes: 1 addition & 1 deletion packages/postcss-purgecss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions> = function (
throw new Error("PurgeCSS plugin does not have the correct options");
return {
postcssPlugin: PLUGIN_NAME,
Once(root, helpers) {
OnceExit(root, helpers) {
return purgeCSS(opts, root, helpers);
},
};
Expand Down