diff --git a/packages/postcss-purgecss/__tests__/fixtures/expected/other-plugins.css b/packages/postcss-purgecss/__tests__/fixtures/expected/other-plugins.css new file mode 100644 index 00000000..ebfe55cf --- /dev/null +++ b/packages/postcss-purgecss/__tests__/fixtures/expected/other-plugins.css @@ -0,0 +1,3 @@ +.prefixed-used-class { + color: black; +} diff --git a/packages/postcss-purgecss/__tests__/fixtures/src/other-plugins/other-plugins.css b/packages/postcss-purgecss/__tests__/fixtures/src/other-plugins/other-plugins.css new file mode 100644 index 00000000..a213a749 --- /dev/null +++ b/packages/postcss-purgecss/__tests__/fixtures/src/other-plugins/other-plugins.css @@ -0,0 +1,11 @@ +.used-class { + color: black; +} + +.unused-class { + color: black; +} + +.another-one-not-found { + color: black; +} diff --git a/packages/postcss-purgecss/__tests__/fixtures/src/other-plugins/other-plugins.html b/packages/postcss-purgecss/__tests__/fixtures/src/other-plugins/other-plugins.html new file mode 100644 index 00000000..3f16cea7 --- /dev/null +++ b/packages/postcss-purgecss/__tests__/fixtures/src/other-plugins/other-plugins.html @@ -0,0 +1,8 @@ + + + + +
+ + + diff --git a/packages/postcss-purgecss/__tests__/index.test.ts b/packages/postcss-purgecss/__tests__/index.test.ts index 39af8816..1446fc44 100644 --- a/packages/postcss-purgecss/__tests__/index.test.ts +++ b/packages/postcss-purgecss/__tests__/index.test.ts @@ -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); + }); }); diff --git a/packages/postcss-purgecss/src/index.ts b/packages/postcss-purgecss/src/index.ts index fe5829dc..d252e32e 100644 --- a/packages/postcss-purgecss/src/index.ts +++ b/packages/postcss-purgecss/src/index.ts @@ -77,7 +77,7 @@ const purgeCSSPlugin: postcss.PluginCreator = 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); }, };