@fullhuman/postcss-purgecss 2.0.5 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,11 +33,28 @@ See [PostCSS] docs for examples for your environment.
33
33
  All of the options of purgecss are available to use with the plugins.
34
34
  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).
35
35
 
36
- ### `content` (**required**)
37
- Type: `string | Object`
36
+ ### `content` (**required** or use `contentFunction` instead)
37
+ Type: `Array<string>`
38
38
 
39
39
  You can specify content that should be analyzed by Purgecss with an array of filenames or globs. The files can be HTML, Pug, Blade, etc.
40
40
 
41
+ ### `contentFunction` (as alternative to `content`)
42
+ Type: `(sourceInputFile: string) => Array<string>`
43
+
44
+ The function receives the current source input file. With this you may provide a specific array of globs for each input. E.g. for
45
+ an angular application only scan the components template counterpart for every component scss file:
46
+
47
+ ```js
48
+ purgecss({
49
+ contentFunction: (sourceInputFileName: string) => {
50
+ if (/component\.scss$/.test(sourceInputFileName))
51
+ return [sourceInputFileName.replace(/scss$/, 'html')]
52
+ else
53
+ return ['./src/**/*.html']
54
+ },
55
+ })
56
+ ```
57
+
41
58
  ### `extractors`
42
59
  Type: `Array<Object>`
43
60
 
@@ -12,7 +12,8 @@ interface Extractors {
12
12
  extractor: ExtractorFunction;
13
13
  }
14
14
  interface UserDefinedOptions {
15
- content: Array<string | RawContent>;
15
+ content?: Array<string | RawContent>;
16
+ contentFunction?: (sourceFile: string) => Array<string | RawContent>;
16
17
  css: Array<string | RawCSS>;
17
18
  defaultExtractor?: ExtractorFunction;
18
19
  extractors?: Array<Extractors>;
@@ -27,5 +28,5 @@ interface UserDefinedOptions {
27
28
  whitelistPatterns?: Array<RegExp>;
28
29
  whitelistPatternsChildren?: Array<RegExp>;
29
30
  }
30
- declare const purgeCSSPlugin: postcss.Plugin<Pick<UserDefinedOptions, "keyframes" | "content" | "extractors" | "defaultExtractor" | "fontFace" | "output" | "rejected" | "stdin" | "stdout" | "variables" | "whitelist" | "whitelistPatterns" | "whitelistPatternsChildren">>;
31
+ declare const purgeCSSPlugin: postcss.Plugin<Pick<UserDefinedOptions, "keyframes" | "content" | "extractors" | "contentFunction" | "defaultExtractor" | "fontFace" | "output" | "rejected" | "stdin" | "stdout" | "variables" | "whitelist" | "whitelistPatterns" | "whitelistPatternsChildren">>;
31
32
  export { purgeCSSPlugin as default };
@@ -12,7 +12,8 @@ interface Extractors {
12
12
  extractor: ExtractorFunction;
13
13
  }
14
14
  interface UserDefinedOptions {
15
- content: Array<string | RawContent>;
15
+ content?: Array<string | RawContent>;
16
+ contentFunction?: (sourceFile: string) => Array<string | RawContent>;
16
17
  css: Array<string | RawCSS>;
17
18
  defaultExtractor?: ExtractorFunction;
18
19
  extractors?: Array<Extractors>;
@@ -27,5 +28,5 @@ interface UserDefinedOptions {
27
28
  whitelistPatterns?: Array<RegExp>;
28
29
  whitelistPatternsChildren?: Array<RegExp>;
29
30
  }
30
- declare const purgeCSSPlugin: postcss.Plugin<Pick<UserDefinedOptions, "keyframes" | "content" | "extractors" | "defaultExtractor" | "fontFace" | "output" | "rejected" | "stdin" | "stdout" | "variables" | "whitelist" | "whitelistPatterns" | "whitelistPatternsChildren">>;
31
+ declare const purgeCSSPlugin: postcss.Plugin<Pick<UserDefinedOptions, "keyframes" | "content" | "extractors" | "contentFunction" | "defaultExtractor" | "fontFace" | "output" | "rejected" | "stdin" | "stdout" | "variables" | "whitelist" | "whitelistPatterns" | "whitelistPatternsChildren">>;
31
32
  export { purgeCSSPlugin as default };
@@ -1 +1 @@
1
- import e from"postcss";import s,{mergeExtractorSelectors as o,defaultOptions as t}from"purgecss";const r=e.plugin("postcss-plugin-purgecss",(function(e){return async function(r,n){const c=new s,i={...t,...e};c.options=i;const{content:p,extractors:a}=i,m=p.filter(e=>"string"==typeof e),l=p.filter(e=>"object"==typeof e),u=await c.extractSelectorsFromFiles(m,a),f=c.extractSelectorsFromString(l,a),g=o(u,f);c.walkThroughCSS(r,g),c.options.fontFace&&c.removeUnusedFontFaces(),c.options.keyframes&&c.removeUnusedKeyframes(),c.options.variables&&c.removeUnusedCSSVariables(),c.options.rejected&&c.selectorsRemoved.size>0&&(n.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${c.selectorsRemoved.size} selectors:\n ${Array.from(c.selectorsRemoved).map(e=>e.trim()).join("\n ")}`}),c.selectorsRemoved.clear())}}));export default r;
1
+ import e from"postcss";import t,{mergeExtractorSelectors as o,defaultOptions as s}from"purgecss";const r=e.plugin("postcss-plugin-purgecss",(function(e){return async function(r,n){const c=new t,i={...s,...e};e&&"function"==typeof e.contentFunction&&(i.content=e.contentFunction(r.source&&r.source.input.file||"")),c.options=i;const{content:p,extractors:u}=i,a=p.filter(e=>"string"==typeof e),l=p.filter(e=>"object"==typeof e),m=await c.extractSelectorsFromFiles(a,u),f=await c.extractSelectorsFromString(l,u),g=o(m,f);c.walkThroughCSS(r,g),c.options.fontFace&&c.removeUnusedFontFaces(),c.options.keyframes&&c.removeUnusedKeyframes(),c.options.variables&&c.removeUnusedCSSVariables(),c.options.rejected&&c.selectorsRemoved.size>0&&(n.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${c.selectorsRemoved.size} selectors:\n ${Array.from(c.selectorsRemoved).map(e=>e.trim()).join("\n ")}`}),c.selectorsRemoved.clear())}}));export default r;
@@ -1 +1 @@
1
- "use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var postcss=_interopDefault(require("postcss")),PurgeCSS=require("purgecss"),PurgeCSS__default=_interopDefault(PurgeCSS);const purgeCSSPlugin=postcss.plugin("postcss-plugin-purgecss",(function(e){return async function(t,s){const r=new PurgeCSS__default,o={...PurgeCSS.defaultOptions,...e};r.options=o;const{content:n,extractors:u}=o,c=n.filter(e=>"string"==typeof e),i=n.filter(e=>"object"==typeof e),p=await r.extractSelectorsFromFiles(c,u),a=r.extractSelectorsFromString(i,u),l=PurgeCSS.mergeExtractorSelectors(p,a);r.walkThroughCSS(t,l),r.options.fontFace&&r.removeUnusedFontFaces(),r.options.keyframes&&r.removeUnusedKeyframes(),r.options.variables&&r.removeUnusedCSSVariables(),r.options.rejected&&r.selectorsRemoved.size>0&&(s.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${r.selectorsRemoved.size} selectors:\n ${Array.from(r.selectorsRemoved).map(e=>e.trim()).join("\n ")}`}),r.selectorsRemoved.clear())}}));module.exports=purgeCSSPlugin;
1
+ "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=e(require("postcss")),s=require("purgecss"),o=e(s);const r=t.plugin("postcss-plugin-purgecss",(function(e){return async function(t,r){const n=new o,c={...s.defaultOptions,...e};e&&"function"==typeof e.contentFunction&&(c.content=e.contentFunction(t.source&&t.source.input.file||"")),n.options=c;const{content:i,extractors:u}=c,a=i.filter(e=>"string"==typeof e),p=i.filter(e=>"object"==typeof e),l=await n.extractSelectorsFromFiles(a,u),f=await n.extractSelectorsFromString(p,u),m=s.mergeExtractorSelectors(l,f);n.walkThroughCSS(t,m),n.options.fontFace&&n.removeUnusedFontFaces(),n.options.keyframes&&n.removeUnusedKeyframes(),n.options.variables&&n.removeUnusedCSSVariables(),n.options.rejected&&n.selectorsRemoved.size>0&&(r.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${n.selectorsRemoved.size} selectors:\n ${Array.from(n.selectorsRemoved).map(e=>e.trim()).join("\n ")}`}),n.selectorsRemoved.clear())}}));module.exports=r;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullhuman/postcss-purgecss",
3
- "version": "2.0.5",
3
+ "version": "2.2.0",
4
4
  "description": "PostCSS plugin for PurgeCSS",
5
5
  "author": "FoundrySH <no-reply@foundry.sh>",
6
6
  "homepage": "https://github.com/FullHuman/purgecss#readme",
@@ -26,8 +26,8 @@
26
26
  "url": "https://github.com/FullHuman/purgecss/issues"
27
27
  },
28
28
  "dependencies": {
29
- "postcss": "7.0.26",
30
- "purgecss": "^2.0.5"
29
+ "postcss": "7.0.28",
30
+ "purgecss": "^2.2.0"
31
31
  },
32
- "gitHead": "a1176c1e2b83e80324e1a2cc75c88d1b795d863a"
32
+ "gitHead": "e7a590b2e20be4de8f8b55a61554f550fe27f69f"
33
33
  }