From ddc66f3c8d398f96743c2ebc8180761fe7c851db Mon Sep 17 00:00:00 2001 From: Daniele Polencic Date: Mon, 4 May 2020 09:37:37 +0800 Subject: [PATCH 01/20] refactor: added generics to extractor function --- packages/gulp-purgecss/src/types/index.ts | 6 +++--- packages/postcss-purgecss/src/types/index.ts | 6 +++--- packages/purgecss-webpack-plugin/src/index.ts | 3 +-- packages/purgecss-webpack-plugin/src/types/index.ts | 6 +++--- packages/purgecss/src/types/index.ts | 6 +++--- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/gulp-purgecss/src/types/index.ts b/packages/gulp-purgecss/src/types/index.ts index f27e7405..6d12094b 100644 --- a/packages/gulp-purgecss/src/types/index.ts +++ b/packages/gulp-purgecss/src/types/index.ts @@ -1,11 +1,11 @@ -export interface RawContent { +export interface RawContent { extension: string; - raw: string; + raw: T; } export interface RawCSS { raw: string; } -type ExtractorFunction = (content: string) => string[]; +type ExtractorFunction = (content: T) => string[]; export interface Extractors { extensions: string[]; extractor: ExtractorFunction; diff --git a/packages/postcss-purgecss/src/types/index.ts b/packages/postcss-purgecss/src/types/index.ts index b96ffca6..88951bdb 100644 --- a/packages/postcss-purgecss/src/types/index.ts +++ b/packages/postcss-purgecss/src/types/index.ts @@ -1,11 +1,11 @@ -export interface RawContent { +export interface RawContent { extension: string; - raw: string; + raw: T; } export interface RawCSS { raw: string; } -type ExtractorFunction = (content: string) => string[]; +type ExtractorFunction = (content: T) => string[]; export interface Extractors { extensions: string[]; extractor: ExtractorFunction; diff --git a/packages/purgecss-webpack-plugin/src/index.ts b/packages/purgecss-webpack-plugin/src/index.ts index 60bc9a25..a718caa5 100644 --- a/packages/purgecss-webpack-plugin/src/index.ts +++ b/packages/purgecss-webpack-plugin/src/index.ts @@ -56,7 +56,6 @@ export default class PurgeCSSPlugin { }); } - initializePlugin(compilation: Compilation): void { compilation.hooks.additionalAssets.tapPromise(pluginName, () => { const entryPaths = @@ -67,7 +66,7 @@ export default class PurgeCSSPlugin { entryPaths.forEach((p) => { if (!fs.existsSync(p)) throw new Error(`Path ${p} does not exist.`); }); - + return this.runPluginHook(compilation, entryPaths); }); } diff --git a/packages/purgecss-webpack-plugin/src/types/index.ts b/packages/purgecss-webpack-plugin/src/types/index.ts index 2a466d97..0381c243 100644 --- a/packages/purgecss-webpack-plugin/src/types/index.ts +++ b/packages/purgecss-webpack-plugin/src/types/index.ts @@ -1,11 +1,11 @@ -export interface RawContent { +export interface RawContent { extension: string; - raw: string; + raw: T; } export interface RawCSS { raw: string; } -type ExtractorFunction = (content: string) => string[]; +type ExtractorFunction = (content: T) => string[]; export interface Extractors { extensions: string[]; extractor: ExtractorFunction; diff --git a/packages/purgecss/src/types/index.ts b/packages/purgecss/src/types/index.ts index df4dc6d1..55da47a2 100644 --- a/packages/purgecss/src/types/index.ts +++ b/packages/purgecss/src/types/index.ts @@ -9,9 +9,9 @@ export interface AtRules { keyframes: postcss.AtRule[]; } -export interface RawContent { +export interface RawContent { extension: string; - raw: string; + raw: T; } export interface RawCSS { @@ -31,7 +31,7 @@ export interface ExtractorResultDetailed { export type ExtractorResult = ExtractorResultDetailed | string[]; -export type ExtractorFunction = (content: string) => ExtractorResult; +export type ExtractorFunction = (content: T) => ExtractorResult; export interface Extractors { extensions: string[]; From 3305398106a6f486cf3c67f77402f0164f235aca Mon Sep 17 00:00:00 2001 From: Tanmay Rajani Date: Fri, 8 May 2020 21:41:00 +0530 Subject: [PATCH 02/20] updates URLs of extractors --- docs/extractors.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/extractors.md b/docs/extractors.md index dc302e81..99dcd163 100644 --- a/docs/extractors.md +++ b/docs/extractors.md @@ -68,7 +68,8 @@ Those extractors are still a work in progress. It is not encourage to use them in production yet. ::: -- [purgecss-from-html](): HTML files (.html) -- [purgecss-from-pug](): Pug files (.pug) +- [purgecss-from-html](https://github.com/FullHuman/purgecss/blob/master/packages/purgecss-from-html): HTML files (.html) +- [purgecss-from-js](https://github.com/FullHuman/purgecss/blob/master/packages/purgecss-from-js): JS files +- [purgecss-from-pug](https://github.com/FullHuman/purgecss/blob/master/packages/purgecss-from-pug): Pug files (.pug) - [purgecss-from-twig](): Twig files -- [purgecss-from-blade](): Blade files \ No newline at end of file +- [purgecss-from-blade](): Blade files From b79351bd0c3aa3ff416a6469b817a9a3aecaffaf Mon Sep 17 00:00:00 2001 From: Michael Bourne Date: Wed, 13 May 2020 11:18:49 -0600 Subject: [PATCH 03/20] Add Gutenberg classes to index.js Better support for Gutenberg related block classes and style classes used by the block editor. --- packages/purgecss-with-wordpress/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/purgecss-with-wordpress/index.js b/packages/purgecss-with-wordpress/index.js index 790938aa..56933f14 100644 --- a/packages/purgecss-with-wordpress/index.js +++ b/packages/purgecss-with-wordpress/index.js @@ -18,6 +18,7 @@ module.exports = { 'wp-caption-text', 'screen-reader-text', 'comment-list', + 'wp-social-link', ], whitelistPatterns: [ /^search(-.*)?$/, @@ -34,5 +35,10 @@ module.exports = { /^tax-(.*)?$/, /^term-(.*)?$/, /^(.*)?-?paged(-.*)?$/, + /^wp-block-(.*)?$/, + /^has-(.*)?$/, + /^is-(.*)?$/, + /^wp-embed-(.*)?$/, + /^blocks-gallery-(.*)?$/, ], }; From 8428eaacc44d3572895023a58e387afb43433d50 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 18 May 2020 09:30:00 +0000 Subject: [PATCH 04/20] build(deps): bump postcss from 7.0.28 to 7.0.30 Bumps [postcss](https://github.com/postcss/postcss) from 7.0.28 to 7.0.30. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/7.0.28...7.0.30) Signed-off-by: dependabot-preview[bot] --- packages/postcss-purgecss/package.json | 2 +- packages/purgecss/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/postcss-purgecss/package.json b/packages/postcss-purgecss/package.json index 229f70c3..0b5307f2 100644 --- a/packages/postcss-purgecss/package.json +++ b/packages/postcss-purgecss/package.json @@ -26,7 +26,7 @@ "url": "https://github.com/FullHuman/purgecss/issues" }, "dependencies": { - "postcss": "7.0.28", + "postcss": "7.0.30", "purgecss": "^2.2.0" } } diff --git a/packages/purgecss/package.json b/packages/purgecss/package.json index 60bec039..e408b9f5 100644 --- a/packages/purgecss/package.json +++ b/packages/purgecss/package.json @@ -41,7 +41,7 @@ "dependencies": { "commander": "^5.0.0", "glob": "^7.0.0", - "postcss": "7.0.28", + "postcss": "7.0.30", "postcss-selector-parser": "^6.0.2" }, "devDependencies": { From 1f5101ca69af5e50f582242feeccc5158400da17 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 18 May 2020 09:33:37 +0000 Subject: [PATCH 05/20] build(deps): bump twing from 4.0.6 to 5.0.1 Bumps [twing](https://github.com/NightlyCommit/twing) from 4.0.6 to 5.0.1. - [Release notes](https://github.com/NightlyCommit/twing/releases) - [Changelog](https://github.com/NightlyCommit/twing/blob/master/CHANGELOG) - [Commits](https://github.com/NightlyCommit/twing/compare/v4.0.6...v5.0.1) Signed-off-by: dependabot-preview[bot] --- packages/purgecss-from-twig/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/purgecss-from-twig/package.json b/packages/purgecss-from-twig/package.json index 1be6ab66..3130e423 100644 --- a/packages/purgecss-from-twig/package.json +++ b/packages/purgecss-from-twig/package.json @@ -24,6 +24,6 @@ "url": "https://github.com/FullHuman/purgecss/issues" }, "dependencies": { - "twing": "^4.0.4" + "twing": "^5.0.1" } } From f05ccadbaa5cfcd12b7bcc64c459963573ff316f Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 25 May 2020 09:39:15 +0000 Subject: [PATCH 06/20] build(deps-dev): bump rollup-plugin-terser from 5.3.0 to 6.1.0 Bumps [rollup-plugin-terser](https://github.com/TrySound/rollup-plugin-terser) from 5.3.0 to 6.1.0. - [Release notes](https://github.com/TrySound/rollup-plugin-terser/releases) - [Commits](https://github.com/TrySound/rollup-plugin-terser/compare/v5.3.0...v6.1.0) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e91fbe00..9ccc5401 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "prettier": "^2.0.4", "rollup": "^2.6.1", "rollup-plugin-node-resolve": "^5.2.0", - "rollup-plugin-terser": "^5.3.0", + "rollup-plugin-terser": "^6.1.0", "ts-jest": "^24.3.0", "ts-node": "^8.8.2", "typescript": "^3.8.3", From 1c0d90887537c9052fdbccb9e8b8fe37eb05b234 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 25 May 2020 09:43:40 +0000 Subject: [PATCH 07/20] build(deps-dev): bump @types/node from 13.13.9 to 14.0.5 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 13.13.9 to 14.0.5. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e91fbe00..c64cba2f 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ ], "devDependencies": { "@types/jest": "^25.2.1", - "@types/node": "^13.13.1", + "@types/node": "^14.0.5", "@typescript-eslint/eslint-plugin": "^2.28.0", "@typescript-eslint/parser": "^2.28.0", "@vuepress/plugin-google-analytics": "^1.4.1", From e82a6643aabbcd3772cee2be186129c7cddf7fe9 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 1 Jun 2020 09:29:10 +0000 Subject: [PATCH 08/20] build(deps-dev): bump pug-lexer from 4.1.0 to 5.0.0 Bumps [pug-lexer](https://github.com/pugjs/pug) from 4.1.0 to 5.0.0. - [Release notes](https://github.com/pugjs/pug/releases) - [Commits](https://github.com/pugjs/pug/compare/pug-lexer@4.1.0...pug-lexer@5.0.0) Signed-off-by: dependabot-preview[bot] --- packages/purgecss-from-pug/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/purgecss-from-pug/package.json b/packages/purgecss-from-pug/package.json index f8d75aa0..0f9bb1ab 100644 --- a/packages/purgecss-from-pug/package.json +++ b/packages/purgecss-from-pug/package.json @@ -24,7 +24,7 @@ "url": "https://github.com/FullHuman/purgecss/issues" }, "devDependencies": { - "pug-lexer": "^4.1.0", + "pug-lexer": "^5.0.0", "pug-parser": "^5.0.1" } } From 8dd6156aed6670d2911581cbff4201c9a6027d11 Mon Sep 17 00:00:00 2001 From: Christian Oliff Date: Mon, 8 Jun 2020 15:35:07 +0900 Subject: [PATCH 09/20] Fix minor typo on WordPress page --- docs/guides/wordpress.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/guides/wordpress.md b/docs/guides/wordpress.md index 1ead1f02..08cb319c 100644 --- a/docs/guides/wordpress.md +++ b/docs/guides/wordpress.md @@ -10,7 +10,7 @@ meta: # WordPress -If you want to use PurgeCSS with WordPress, you might need to whitelist classes generated by WordPress to avoid them being remove by PurgeCSS. `purgecss-with-wordpress` contains the classes needed to be whitelisted. +If you want to use PurgeCSS with WordPress, you might need to whitelist classes generated by WordPress to avoid them being removed by PurgeCSS. `purgecss-with-wordpress` contains the classes needed to be whitelisted. ## Installation @@ -51,4 +51,4 @@ If you have additional classes you want to include in either of the `whitelist` /blue$/, ] } -``` \ No newline at end of file +``` From 4bef3ec6218b406244ad86e536f83f4c0768288d Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 8 Jun 2020 09:12:32 +0000 Subject: [PATCH 10/20] build(deps-dev): bump @types/webpack-sources from 0.1.8 to 1.4.0 Bumps [@types/webpack-sources](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/webpack-sources) from 0.1.8 to 1.4.0. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/webpack-sources) Signed-off-by: dependabot-preview[bot] --- packages/purgecss-webpack-plugin/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/purgecss-webpack-plugin/package.json b/packages/purgecss-webpack-plugin/package.json index a4202280..127ffe27 100644 --- a/packages/purgecss-webpack-plugin/package.json +++ b/packages/purgecss-webpack-plugin/package.json @@ -45,7 +45,7 @@ }, "devDependencies": { "@types/webpack": "^4.41.12", - "@types/webpack-sources": "^0.1.7", + "@types/webpack-sources": "^1.4.0", "css-loader": "^3.5.2", "mini-css-extract-plugin": "^0.9.0" }, From 568da8022b1d200d61063592f269a18f591de4b4 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 8 Jun 2020 09:19:16 +0000 Subject: [PATCH 11/20] build(deps): bump postcss from 7.0.30 to 7.0.32 Bumps [postcss](https://github.com/postcss/postcss) from 7.0.30 to 7.0.32. - [Release notes](https://github.com/postcss/postcss/releases) - [Changelog](https://github.com/postcss/postcss/blob/master/CHANGELOG.md) - [Commits](https://github.com/postcss/postcss/compare/7.0.30...7.0.32) Signed-off-by: dependabot-preview[bot] --- packages/postcss-purgecss/package.json | 2 +- packages/purgecss/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/postcss-purgecss/package.json b/packages/postcss-purgecss/package.json index 0b5307f2..678ab663 100644 --- a/packages/postcss-purgecss/package.json +++ b/packages/postcss-purgecss/package.json @@ -26,7 +26,7 @@ "url": "https://github.com/FullHuman/purgecss/issues" }, "dependencies": { - "postcss": "7.0.30", + "postcss": "7.0.32", "purgecss": "^2.2.0" } } diff --git a/packages/purgecss/package.json b/packages/purgecss/package.json index e408b9f5..cf6972c5 100644 --- a/packages/purgecss/package.json +++ b/packages/purgecss/package.json @@ -41,7 +41,7 @@ "dependencies": { "commander": "^5.0.0", "glob": "^7.0.0", - "postcss": "7.0.30", + "postcss": "7.0.32", "postcss-selector-parser": "^6.0.2" }, "devDependencies": { From 02e0d70398c87977d253fad36337891399196057 Mon Sep 17 00:00:00 2001 From: Patrick Hill Date: Wed, 10 Jun 2020 12:49:29 -0400 Subject: [PATCH 12/20] content path needs to be in quotes for globs to work --- docs/CLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CLI.md b/docs/CLI.md index c4f1d57d..4c9c471e 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -68,7 +68,7 @@ purgecss --config ./purgecss.config.js By default, the CLI outputs the result in the console. If you wish to return the CSS as files, specify the directory to write the purified CSS files to. ```text -purgecss --css css/app.css --content src/index.html,src/**/*.js --output build/css/ +purgecss --css css/app.css --content src/index.html,"src/**/*.js" --output build/css/ ``` ### --whitelist From 7cc372fc659d9761ffec565a334d8506bca1a316 Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 14:15:56 +0100 Subject: [PATCH 13/20] fix: remove buggy stdin CLI feature caused issue #405 --- packages/purgecss/bin/purgecss | 14 ++++++-------- packages/purgecss/package.json | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/purgecss/bin/purgecss b/packages/purgecss/bin/purgecss index f2a62682..dad60e5e 100755 --- a/packages/purgecss/bin/purgecss +++ b/packages/purgecss/bin/purgecss @@ -28,11 +28,9 @@ program program.parse(process.argv); -const stdInCSS = fs.readFileSync(0).toString(); - // config file is not specified or the content and css are not, // PurgeCSS will not run -if (!program.config && !(program.content && (program.css || stdInCSS))) { +if (!program.config && !(program.content && program.css)) { program.help(); } @@ -51,11 +49,11 @@ if (!program.config && !(program.content && (program.css || stdInCSS))) { if (program.variables) options.variables = program.variables; if (program.whitelist) options.whitelist = program.whitelist; - if (!options.css) { - options.css = [{ - raw: stdInCSS - }] - } + // if (!options.css) { + // options.css = [{ + // raw: stdInCSS + // }] + // } const purged = await new PurgeCSS().purge(options); diff --git a/packages/purgecss/package.json b/packages/purgecss/package.json index cf6972c5..6ad6ab8a 100644 --- a/packages/purgecss/package.json +++ b/packages/purgecss/package.json @@ -1,6 +1,6 @@ { "name": "purgecss", - "version": "2.2.0", + "version": "2.2.1", "description": "Remove unused css selectors", "author": "Ffloriel", "homepage": "https://purgecss.com", From 47a837c04f8c63fe4c0f87ef6ebe1d645e0a31b6 Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 14:33:12 +0100 Subject: [PATCH 14/20] docs: add main options to the postcss page issue #407 --- docs/plugins/postcss.md | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/plugins/postcss.md b/docs/plugins/postcss.md index 121e0190..cc23d70d 100644 --- a/docs/plugins/postcss.md +++ b/docs/plugins/postcss.md @@ -48,4 +48,29 @@ See [PostCSS](https://github.com/postcss/postcss) documentation for examples for ## Options All of the options of PurgeCSS are available to use with the plugins. -You will find below the main options available. For the complete list, go to the [PurgeCSS documentation website](https://www.purgecss.com/configuration.html#options). +You will find below the type definition of the main options available. For the complete list, go to the [PurgeCSS documentation website](https://www.purgecss.com/configuration.html#options). + +```ts +interface UserDefinedOptions { + content: Array + css: Array + defaultExtractor?: ExtractorFunction + extractors?: Array + fontFace?: boolean + keyframes?: boolean + output?: string + variables?: boolean + whitelist?: string[] + whitelistPatterns?: Array + whitelistPatternsChildren?: Array +} + +interface RawContent { + extension: string + raw: string +} + +interface RawCSS { + raw: string +} +``` From 6f5d95829ca19bd8ab980ca415575166b23629d7 Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 14:54:58 +0100 Subject: [PATCH 15/20] docs: add how to use with ant-design https://github.com/FullHuman/purgecss/issues/172 --- docs/.vuepress/config.js | 167 ++++++++++++++++++++------------------- docs/ant_design.md | 73 +++++++++++++++++ 2 files changed, 157 insertions(+), 83 deletions(-) create mode 100644 docs/ant_design.md diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index bc5dcae1..45cde807 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -1,141 +1,142 @@ module.exports = { head: [ [ - 'link', + "link", { - rel: 'apple-touch-icon', - sizes: '180x180', - href: '/apple-touch-icon.png' - } + rel: "apple-touch-icon", + sizes: "180x180", + href: "/apple-touch-icon.png", + }, ], [ - 'link', + "link", { - rel: 'icon', - type: 'image/png', - sizes: '32x32', - href: '/favicon-32x32.png' - } + rel: "icon", + type: "image/png", + sizes: "32x32", + href: "/favicon-32x32.png", + }, ], [ - 'link', + "link", { - rel: 'icon', - type: 'image/png', - sizes: '16x16', - href: '/favicon-16x16.png' - } + rel: "icon", + type: "image/png", + sizes: "16x16", + href: "/favicon-16x16.png", + }, ], [ - 'link', + "link", { - rel: 'manifest', - href: '/site.webmanifest' - } + rel: "manifest", + href: "/site.webmanifest", + }, ], [ - 'link', + "link", { - rel: 'mask-icon', - href: '/safari-pinned-tab.svg', - color: '#000000' - } + rel: "mask-icon", + href: "/safari-pinned-tab.svg", + color: "#000000", + }, ], [ - 'meta', + "meta", { - name: 'msapplication-TileColor', - content: '#ffffff' - } + name: "msapplication-TileColor", + content: "#ffffff", + }, ], [ - 'meta', + "meta", { - name: 'theme-color', - content: '#ffffff' - } + name: "theme-color", + content: "#ffffff", + }, ], [ - 'script', + "script", { async: true, - src: 'https://www.googletagmanager.com/gtag/js?id=UA-117085901-1' - } + src: "https://www.googletagmanager.com/gtag/js?id=UA-117085901-1", + }, ], [ - 'script', + "script", {}, `window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); - gtag('config', 'UA-117085901-1');` - ] + gtag('config', 'UA-117085901-1');`, + ], ], themeConfig: { - logo: 'https://i.imgur.com/UEiUiJ0.png', - searchPlaceholder: 'Search...', - repo: 'FullHuman/purgecss', - docsDir: 'docs', - docsBranch: 'master', + logo: "https://i.imgur.com/UEiUiJ0.png", + searchPlaceholder: "Search...", + repo: "FullHuman/purgecss", + docsDir: "docs", + docsBranch: "master", editLinks: true, - editLinkText: 'Help us improve this page!', + editLinkText: "Help us improve this page!", evergreen: true, plugins: [ [ - '@vuepress/google-analytics', + "@vuepress/google-analytics", { - ga: 'UA-117085901-1' - } - ] + ga: "UA-117085901-1", + }, + ], ], sidebar: { - '/': [ + "/": [ { - title: 'PurgeCSS', + title: "PurgeCSS", collapsable: false, children: [ - ['', 'About PurgeCSS'], - ['configuration', 'Configuration'], - ['CLI', 'Command Line Interface'], - ['api', 'Programmatic API'], - ['whitelisting', 'Whitelisting'], - ['extractors', 'Extractors'] - ] + ["", "About PurgeCSS"], + ["configuration", "Configuration"], + ["CLI", "Command Line Interface"], + ["api", "Programmatic API"], + ["whitelisting", "Whitelisting"], + ["extractors", "Extractors"], + ], }, { - title: 'Plugins', + title: "Plugins", collapsable: false, children: [ - ['plugins/postcss', 'PostCSS'], - ['plugins/webpack', 'Webpack'], - ['plugins/gulp', 'Gulp'], - ['plugins/grunt', 'Grunt'], - ['plugins/gatsby', 'Gatsby'] - ] + ["plugins/postcss", "PostCSS"], + ["plugins/webpack", "Webpack"], + ["plugins/gulp", "Gulp"], + ["plugins/grunt", "Grunt"], + ["plugins/gatsby", "Gatsby"], + ], }, { - title: 'Guides', + title: "Guides", collapsable: false, children: [ - ['guides/vue', 'Vue'], - ['guides/react', 'React'], - ['guides/next', 'Next.js'], - ['guides/nuxt', 'Nuxt.js'], - ['guides/razzle', 'Razzle'], - ['guides/wordpress', 'WordPress'] - ] + ["guides/vue", "Vue"], + ["guides/react", "React"], + ["guides/next", "Next.js"], + ["guides/nuxt", "Nuxt.js"], + ["guides/razzle", "Razzle"], + ["guides/wordpress", "WordPress"], + ], }, - ['comparison', 'Comparison'], + ["comparison", "Comparison"], { - title: 'Common Questions', + title: "Common Questions", collapsable: false, children: [ // ["node_modules", "How to use with node modules"], - ['css_modules', 'How to use with CSS modules'] - ] - } - ] - } - } -} + ["css_modules", "How to use with CSS modules"], + ["ant_design", "How to use with Ant Design"], + ], + }, + ], + }, + }, +}; diff --git a/docs/ant_design.md b/docs/ant_design.md new file mode 100644 index 00000000..a300207e --- /dev/null +++ b/docs/ant_design.md @@ -0,0 +1,73 @@ +--- +title: Ant Design | PurgeCSS +lang: en-US +meta: + - name: description + content: PurgeCSS can be used with Ant Design but requires to create a custom CSS extractor. + - name: keywords + content: PurgeCSS Ant Design and-design common question +--- + +# How to use with Ant Design + +::: tip +The content of this page comes from [this issue](https://github.com/FullHuman/purgecss/issues/172#issuecomment-637045325). +::: + +PurgeCSS works by comparing the selectors in your content files with the ones on your CSS files. When using component libraries with their own CSS, it happens the CSS is removed because the content is not found. You then need to specify where the content can be found. + +In the case of ant-design, the list of selectors used in ant-design cannot be retrieve easily from its content. + +Below is a way to use PurgeCSS with Ant Design and React. +The project was created with create-react-app. Then, it is using react-app-rewired to extend the configuration. + + +```js +const glob = require("glob-all"); +const paths = require("react-scripts/config/paths"); + +const { override, addPostcssPlugins } = require("customize-cra"); + +const purgecss = require("@fullhuman/postcss-purgecss")({ + content: [ + paths.appHtml, + ...glob.sync(`${paths.appSrc}/**/*.js`, { nodir: true }), + ...glob.sync(`${paths.appNodeModules}/antd/es/button/**/*.css`, { + nodir: true, + }), + ], + extractors: [ + { + extractor: (content) => content.match(/([a-zA-Z-]+)(?= {)/g) || [], + extensions: ["css"], + }, + ], +}); + +module.exports = override( + addPostcssPlugins([ + ...(process.env.NODE_ENV === "production" ? [purgecss] : []), + ]) +); +``` + +I essentially added a path to the antd css file that I want to keep. in the example below, `button`. + +```js +...glob.sync(`${paths.appNodeModules}/antd/es/button/**/*.css`, +``` + +To keep antd entirely, you could replace by +```js +...glob.sync(`${paths.appNodeModules}/antd/es/**/*.css`, +``` + +and wrote an extractor for css file that intend to get the selectors from the file: +```js + extractors: [ + { + extractor: (content) => content.match(/([a-zA-Z-]+)(?= {)/g) || [], + extensions: ["css"], + }, + ], +``` From 89739f7960604b4309b41fde5892da1b1672c92c Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 15:30:53 +0100 Subject: [PATCH 16/20] docs: add tip to use either webpack or postcss plugin #417 --- docs/plugins/webpack.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/plugins/webpack.md b/docs/plugins/webpack.md index f0bcf965..46fc099c 100644 --- a/docs/plugins/webpack.md +++ b/docs/plugins/webpack.md @@ -10,6 +10,10 @@ meta: # Webpack +:::tip +You can use either the Webpack plugin directly in your webpack configuration or use the [PostCSS plugin](postcss.md) when you are using the Webpack postCSS loader. +::: + ## Installation ```sh From 94203b1190a38158dced55859ca13771fc8e7be6 Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 17:21:40 +0100 Subject: [PATCH 17/20] fix: glob filter out directories add nodir true to glob #430 --- packages/purgecss/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/purgecss/src/index.ts b/packages/purgecss/src/index.ts index ed93c1ca..d040a78a 100644 --- a/packages/purgecss/src/index.ts +++ b/packages/purgecss/src/index.ts @@ -340,7 +340,7 @@ class PurgeCSS { await asyncFs.access(globfile, fs.constants.F_OK); filesNames.push(globfile); } catch (err) { - filesNames = glob.sync(globfile); + filesNames = glob.sync(globfile, { nodir: true }); } for (const file of filesNames) { const content = await asyncFs.readFile(file, "utf-8"); @@ -483,7 +483,7 @@ class PurgeCSS { const processedOptions: Array = []; for (const option of cssOptions) { if (typeof option === "string") { - processedOptions.push(...glob.sync(option)); + processedOptions.push(...glob.sync(option, { nodir: true })); } else { processedOptions.push(option); } From 52d9858de043b72af32cce342f10751b93b2eab6 Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 18:24:35 +0100 Subject: [PATCH 18/20] docs: remove v1 note in README --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index 29626a81..d04a94e0 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,6 @@ When you are building a website, chances are that you are using a css framework This is where PurgeCSS comes into play. PurgeCSS analyzes your content and your css files. Then it matches the selectors used in your files with the one in your content files. It removes unused selectors from your css, resulting in smaller css files. -## Version 1 - -If you are looking for [PurgeCSS 1](https://github.com/FullHuman/purgecss/tree/v1), the documentation is [here](https://v1.purgecss.com) - ## Documentation You can find the PurgeCSS documentation on [this website](https://purgecss.com). From 6a569173d799e0a5d8a6e7160cb677b6b7cc1595 Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 18:32:56 +0100 Subject: [PATCH 19/20] build: update lerna version to correct number - update lerna version to correct number - add generate-changelog npm script --- lerna.json | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lerna.json b/lerna.json index 3a5660fd..af954df7 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "packages": [ "packages/*" ], - "version": "2.2.0" + "version": "2.2.1" } diff --git a/package.json b/package.json index 622419b1..0ca37d77 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,8 @@ "docs:deploy": "firebase deploy", "lint": "eslint . --ext .ts --ignore-path .gitignore --fix", "prettier": "prettier --write --parser typescript '**/*.ts'", - "test": "jest" + "test": "jest", + "generate-changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" }, "husky": { "hooks": { From 5314e41edf328e2ad2639549e1587b82a964a42e Mon Sep 17 00:00:00 2001 From: Ffloriel Date: Sat, 13 Jun 2020 18:33:20 +0100 Subject: [PATCH 20/20] build: 2.3.0 --- lerna.json | 2 +- packages/grunt-purgecss/package.json | 4 ++-- packages/gulp-purgecss/package.json | 4 ++-- packages/postcss-purgecss/package.json | 4 ++-- packages/purgecss-from-pug/package.json | 2 +- packages/purgecss-from-twig/package.json | 2 +- packages/purgecss-webpack-plugin/package.json | 4 ++-- packages/purgecss-with-wordpress/package.json | 2 +- packages/purgecss/package.json | 2 +- 9 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lerna.json b/lerna.json index af954df7..75e90219 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "packages": [ "packages/*" ], - "version": "2.2.1" + "version": "2.3.0" } diff --git a/packages/grunt-purgecss/package.json b/packages/grunt-purgecss/package.json index 58df3280..86e47c70 100644 --- a/packages/grunt-purgecss/package.json +++ b/packages/grunt-purgecss/package.json @@ -1,6 +1,6 @@ { "name": "grunt-purgecss", - "version": "2.2.0", + "version": "2.3.0", "description": "Grunt plugin for PurgeCSS", "author": "Ffloriel", "homepage": "https://purgecss.com", @@ -30,7 +30,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "purgecss": "^2.2.0" + "purgecss": "^2.3.0" }, "devDependencies": { "@types/grunt": "^0.4.25", diff --git a/packages/gulp-purgecss/package.json b/packages/gulp-purgecss/package.json index f6777bd9..cfeddfab 100644 --- a/packages/gulp-purgecss/package.json +++ b/packages/gulp-purgecss/package.json @@ -1,6 +1,6 @@ { "name": "gulp-purgecss", - "version": "2.2.0", + "version": "2.3.0", "description": "Gulp plugin for purgecss", "author": "Ffloriel", "homepage": "https://purgecss.com", @@ -37,7 +37,7 @@ "dependencies": { "glob": "^7.1.6", "plugin-error": "^1.0.1", - "purgecss": "^2.2.0", + "purgecss": "^2.3.0", "through2": "^3.0.1" }, "devDependencies": { diff --git a/packages/postcss-purgecss/package.json b/packages/postcss-purgecss/package.json index 678ab663..503b3d29 100644 --- a/packages/postcss-purgecss/package.json +++ b/packages/postcss-purgecss/package.json @@ -1,6 +1,6 @@ { "name": "@fullhuman/postcss-purgecss", - "version": "2.2.0", + "version": "2.3.0", "description": "PostCSS plugin for PurgeCSS", "author": "FoundrySH ", "homepage": "https://github.com/FullHuman/purgecss#readme", @@ -27,6 +27,6 @@ }, "dependencies": { "postcss": "7.0.32", - "purgecss": "^2.2.0" + "purgecss": "^2.3.0" } } diff --git a/packages/purgecss-from-pug/package.json b/packages/purgecss-from-pug/package.json index 0f9bb1ab..a830f669 100644 --- a/packages/purgecss-from-pug/package.json +++ b/packages/purgecss-from-pug/package.json @@ -1,6 +1,6 @@ { "name": "purgecss-from-pug", - "version": "2.1.2", + "version": "2.3.0", "description": "Pug extractor for PurgeCSS", "author": "Ffloriel", "homepage": "https://github.com/FullHuman/purgecss#readme", diff --git a/packages/purgecss-from-twig/package.json b/packages/purgecss-from-twig/package.json index 3130e423..48663ff2 100644 --- a/packages/purgecss-from-twig/package.json +++ b/packages/purgecss-from-twig/package.json @@ -1,6 +1,6 @@ { "name": "purgecss-from-twig", - "version": "2.2.0", + "version": "2.3.0", "description": "Twig extractor for PurgeCSS", "author": "Ffloriel", "homepage": "https://github.com/FullHuman/purgecss#readme", diff --git a/packages/purgecss-webpack-plugin/package.json b/packages/purgecss-webpack-plugin/package.json index 127ffe27..e394cd0b 100644 --- a/packages/purgecss-webpack-plugin/package.json +++ b/packages/purgecss-webpack-plugin/package.json @@ -1,6 +1,6 @@ { "name": "purgecss-webpack-plugin", - "version": "2.2.0", + "version": "2.3.0", "description": "PurgeCSS plugin for webpack - Remove unused css", "author": "Ffloriel", "homepage": "https://purgecss.com", @@ -36,7 +36,7 @@ "test": "echo \"Error: run tests from root\" && exit 1" }, "dependencies": { - "purgecss": "^2.2.0", + "purgecss": "^2.3.0", "webpack": "^4.42.1", "webpack-sources": "^1.4.3" }, diff --git a/packages/purgecss-with-wordpress/package.json b/packages/purgecss-with-wordpress/package.json index 83648a4e..3831dce8 100644 --- a/packages/purgecss-with-wordpress/package.json +++ b/packages/purgecss-with-wordpress/package.json @@ -1,6 +1,6 @@ { "name": "purgecss-with-wordpress", - "version": "2.1.0", + "version": "2.3.0", "description": "PurgeCSS with wordpress", "author": "Ffloriel", "homepage": "https://purgecss.com", diff --git a/packages/purgecss/package.json b/packages/purgecss/package.json index 6ad6ab8a..5105389c 100644 --- a/packages/purgecss/package.json +++ b/packages/purgecss/package.json @@ -1,6 +1,6 @@ { "name": "purgecss", - "version": "2.2.1", + "version": "2.3.0", "description": "Remove unused css selectors", "author": "Ffloriel", "homepage": "https://purgecss.com",