postcss-purgecss
Advanced tools
Comparing version 2.0.3 to 5.0.0
@@ -1,31 +0,164 @@ | ||
import postcss from "postcss"; | ||
interface RawContent { | ||
extension: string; | ||
raw: string; | ||
/** | ||
* PostCSS Plugin for PurgeCSS | ||
* | ||
* Most bundlers and frameworks to build websites are using PostCSS. | ||
* The easiest way to configure PurgeCSS is with its PostCSS plugin. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
import * as postcss from 'postcss'; | ||
/** | ||
* @public | ||
*/ | ||
export declare type ComplexSafelist = { | ||
standard?: StringRegExpArray; | ||
/** | ||
* You can safelist selectors and their children based on a regular | ||
* expression with `safelist.deep` | ||
* | ||
* @example | ||
* | ||
* ```ts | ||
* const purgecss = await new PurgeCSS().purge({ | ||
* content: [], | ||
* css: [], | ||
* safelist: { | ||
* deep: [/red$/] | ||
* } | ||
* }) | ||
* ``` | ||
* | ||
* In this example, selectors such as `.bg-red .child-of-bg` will be left | ||
* in the final CSS, even if `child-of-bg` is not found. | ||
* | ||
*/ | ||
deep?: RegExp[]; | ||
greedy?: RegExp[]; | ||
variables?: StringRegExpArray; | ||
keyframes?: StringRegExpArray; | ||
}; | ||
/** | ||
* @public | ||
*/ | ||
export declare type ExtractorFunction<T = string> = (content: T) => ExtractorResult; | ||
/** | ||
* @public | ||
*/ | ||
export declare type ExtractorResult = ExtractorResultDetailed | string[]; | ||
/** | ||
* @public | ||
*/ | ||
export declare interface ExtractorResultDetailed { | ||
attributes: { | ||
names: string[]; | ||
values: string[]; | ||
}; | ||
classes: string[]; | ||
ids: string[]; | ||
tags: string[]; | ||
undetermined: string[]; | ||
} | ||
interface RawCSS { | ||
raw: string; | ||
} | ||
type ExtractorFunction = (content: string) => string[]; | ||
interface Extractors { | ||
/** | ||
* @public | ||
*/ | ||
export declare interface Extractors { | ||
extensions: string[]; | ||
extractor: ExtractorFunction; | ||
} | ||
interface UserDefinedOptions { | ||
/** | ||
* PostCSS Plugin for PurgeCSS | ||
* | ||
* @param opts - PurgeCSS Options | ||
* @returns the postCSS plugin | ||
* | ||
* @public | ||
*/ | ||
declare const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions>; | ||
export default purgeCSSPlugin; | ||
/** | ||
* Options used by PurgeCSS to remove unused CSS | ||
* | ||
* @public | ||
*/ | ||
export declare interface PurgeCSSUserDefinedOptions { | ||
/** {@inheritDoc purgecss#Options.content} */ | ||
content: Array<string | RawContent>; | ||
/** {@inheritDoc purgecss#Options.css} */ | ||
css: Array<string | RawCSS>; | ||
/** {@inheritDoc purgecss#Options.defaultExtractor} */ | ||
defaultExtractor?: ExtractorFunction; | ||
/** {@inheritDoc purgecss#Options.extractors} */ | ||
extractors?: Array<Extractors>; | ||
/** {@inheritDoc purgecss#Options.fontFace} */ | ||
fontFace?: boolean; | ||
/** {@inheritDoc purgecss#Options.keyframes} */ | ||
keyframes?: boolean; | ||
/** {@inheritDoc purgecss#Options.output} */ | ||
output?: string; | ||
/** {@inheritDoc purgecss#Options.rejected} */ | ||
rejected?: boolean; | ||
/** {@inheritDoc purgecss#Options.rejectedCss} */ | ||
rejectedCss?: boolean; | ||
/** {@inheritDoc purgecss#Options.sourceMap } */ | ||
sourceMap?: boolean | (postcss.SourceMapOptions & { to?: string }); | ||
/** {@inheritDoc purgecss#Options.stdin} */ | ||
stdin?: boolean; | ||
/** {@inheritDoc purgecss#Options.stdout} */ | ||
stdout?: boolean; | ||
/** {@inheritDoc purgecss#Options.variables} */ | ||
variables?: boolean; | ||
whitelist?: string[]; | ||
whitelistPatterns?: Array<RegExp>; | ||
whitelistPatternsChildren?: Array<RegExp>; | ||
/** {@inheritDoc purgecss#Options.safelist} */ | ||
safelist?: UserDefinedSafelist; | ||
/** {@inheritDoc purgecss#Options.blocklist} */ | ||
blocklist?: StringRegExpArray; | ||
/** {@inheritDoc purgecss#Options.skippedContentGlobs} */ | ||
skippedContentGlobs?: Array<string>; | ||
/** {@inheritDoc purgecss#Options.dynamicAttributes} */ | ||
dynamicAttributes?: string[]; | ||
} | ||
declare const purgeCSSPlugin: postcss.Plugin<Pick<UserDefinedOptions, "keyframes" | "content" | "extractors" | "defaultExtractor" | "fontFace" | "output" | "rejected" | "stdin" | "stdout" | "variables" | "whitelist" | "whitelistPatterns" | "whitelistPatternsChildren">>; | ||
export { purgeCSSPlugin as default }; | ||
/** | ||
* @public | ||
*/ | ||
export declare interface RawContent<T = string> { | ||
extension: string; | ||
raw: T; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare interface RawCSS { | ||
raw: string; | ||
name?: string; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare type StringRegExpArray = Array<RegExp | string>; | ||
/** | ||
* {@inheritDoc purgecss#UserDefinedOptions} | ||
* | ||
* @public | ||
*/ | ||
export declare interface UserDefinedOptions extends Omit<PurgeCSSUserDefinedOptions, "content" | "css"> { | ||
content?: PurgeCSSUserDefinedOptions["content"]; | ||
contentFunction?: (sourceFile: string) => Array<string | RawContent>; | ||
} | ||
/** | ||
* @public | ||
*/ | ||
export declare type UserDefinedSafelist = StringRegExpArray | ComplexSafelist; | ||
export { } |
@@ -1,1 +0,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; | ||
import*as e from"path";import{PurgeCSS as s,defaultOptions as t,standardizeSafelist as o,mergeExtractorSelectors as r}from"purgecss";const n=function(n){if(void 0===n)throw new Error("PurgeCSS plugin does not have the correct options");return{postcssPlugin:"postcss-purgecss",OnceExit:(c,i)=>async function(n,c,{result:i}){const a=new s;let l;try{const s=e.resolve(process.cwd(),"purgecss.config.js");l=await import(s)}catch{}const p={...t,...l,...n,safelist:o((null==n?void 0:n.safelist)||(null==l?void 0:l.safelist))};n&&"function"==typeof n.contentFunction&&(p.content=n.contentFunction(c.source&&c.source.input.file||"")),a.options=p,p.variables&&(a.variablesStructure.safelist=p.safelist.variables||[]);const{content:u,extractors:f}=p,m=u.filter((e=>"string"==typeof e)),g=u.filter((e=>"object"==typeof e)),v=await a.extractSelectorsFromFiles(m,f),d=await a.extractSelectorsFromString(g,f),S=r(v,d);a.walkThroughCSS(c,S),a.options.fontFace&&a.removeUnusedFontFaces(),a.options.keyframes&&a.removeUnusedKeyframes(),a.options.variables&&a.removeUnusedCSSVariables(),a.options.rejected&&a.selectorsRemoved.size>0&&(i.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${a.selectorsRemoved.size} selectors:\n ${Array.from(a.selectorsRemoved).map((e=>e.trim())).join("\n ")}`}),a.selectorsRemoved.clear())}(n,c,i)}};n.postcss=!0;export{n as default}; |
@@ -1,1 +0,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; | ||
"use strict";var e=require("path"),t=require("purgecss");function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=r(e);const o=function(e){if(void 0===e)throw new Error("PurgeCSS plugin does not have the correct options");return{postcssPlugin:"postcss-purgecss",OnceExit:(o,n)=>async function(e,o,{result:n}){const c=new t.PurgeCSS;let i;try{const e=s.resolve(process.cwd(),"purgecss.config.js");i=await function(e){return Promise.resolve().then((function(){return r(require(e))}))}(e)}catch{}const a={...t.defaultOptions,...i,...e,safelist:t.standardizeSafelist((null==e?void 0:e.safelist)||(null==i?void 0:i.safelist))};e&&"function"==typeof e.contentFunction&&(a.content=e.contentFunction(o.source&&o.source.input.file||"")),c.options=a,a.variables&&(c.variablesStructure.safelist=a.safelist.variables||[]);const{content:u,extractors:l}=a,f=u.filter((e=>"string"==typeof e)),p=u.filter((e=>"object"==typeof e)),d=await c.extractSelectorsFromFiles(f,l),g=await c.extractSelectorsFromString(p,l),v=t.mergeExtractorSelectors(d,g);c.walkThroughCSS(o,v),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())}(e,o,n)}};o.postcss=!0,module.exports=o; |
{ | ||
"name": "postcss-purgecss", | ||
"version": "2.0.3", | ||
"version": "5.0.0", | ||
"description": "PostCSS plugin for PurgeCSS", | ||
"author": "FoundrySH <no-reply@foundry.sh>", | ||
"homepage": "https://github.com/FullHuman/purgecss#readme", | ||
"homepage": "https://purgecss.com", | ||
"license": "MIT", | ||
@@ -23,3 +23,4 @@ "main": "lib/postcss-purgecss.js", | ||
"scripts": { | ||
"test": "echo \"Error: run tests from root\" && exit 1" | ||
"build": "ts-node build.ts", | ||
"test": "jest" | ||
}, | ||
@@ -30,6 +31,14 @@ "bugs": { | ||
"dependencies": { | ||
"postcss": "7.0.26", | ||
"purgecss": "^2.0.3" | ||
"purgecss": "^5.0.0" | ||
}, | ||
"gitHead": "8219ff4f78e3fbea93a2e2aceeaef83be3659831" | ||
"devDependencies": { | ||
"postcss": "^8.4.4" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} |
# PostCSS Purgecss | ||
[![Build Status](https://travis-ci.org/FullHuman/postcss-purgecss.svg?branch=master)](https://travis-ci.org/FullHuman/postcss-purgecss) | ||
[![CircleCi](https://circleci.com/gh/FullHuman/postcss-purgecss/tree/master.svg?style=shield)]() | ||
[![dependencies Status](https://david-dm.org/fullhuman/postcss-purgecss/status.svg)](https://david-dm.org/fullhuman/postcss-purgecss) | ||
[![devDependencies Status](https://david-dm.org/fullhuman/postcss-purgecss/dev-status.svg)](https://david-dm.org/fullhuman/postcss-purgecss?type=dev) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/2554f9858cb742ed93eb22f49ccec3c3)](https://www.codacy.com/app/FullHuman/postcss-purgecss?utm_source=github.com&utm_medium=referral&utm_content=FullHuman/postcss-purgecss&utm_campaign=Badge_Grade) | ||
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/2554f9858cb742ed93eb22f49ccec3c3)](https://www.codacy.com/app/FullHuman/postcss-purgecss?utm_source=github.com&utm_medium=referral&utm_content=FullHuman/postcss-purgecss&utm_campaign=Badge_Coverage) | ||
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) | ||
[![npm](https://img.shields.io/npm/v/postcss-purgecss.svg)](https://www.npmjs.com/package/@fullhuman/postcss-purgecss) | ||
[![license](https://img.shields.io/github/license/fullhuman/postcss-purgecss.svg)]() [![Greenkeeper badge](https://badges.greenkeeper.io/FullHuman/postcss-purgecss.svg)](https://greenkeeper.io/) | ||
![David (path)](https://img.shields.io/david/FullHuman/purgecss?path=packages%2Fpostcss-purgecss&style=for-the-badge) | ||
![Dependabot](https://img.shields.io/badge/dependabot-enabled-%23024ea4?style=for-the-badge) | ||
![npm](https://img.shields.io/npm/v/@fullhuman/postcss-purgecss?style=for-the-badge) | ||
![npm](https://img.shields.io/npm/dw/@fullhuman/postcss-purgecss?style=for-the-badge) | ||
![GitHub](https://img.shields.io/github/license/FullHuman/purgecss?style=for-the-badge) | ||
@@ -19,3 +15,3 @@ [PostCSS] plugin for PurgeCSS. | ||
``` | ||
npm i -D @fullhuman/postcss-purgecss | ||
npm i -D @fullhuman/postcss-purgecss postcss | ||
``` | ||
@@ -41,7 +37,24 @@ | ||
### `content` (**required**) | ||
Type: `string | Object` | ||
### `content` (**required** or use `contentFunction` instead) | ||
Type: `Array<string>` | ||
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. | ||
### `contentFunction` (as alternative to `content`) | ||
Type: `(sourceInputFile: string) => Array<string>` | ||
The function receives the current source input file. With this you may provide a specific array of globs for each input. E.g. for | ||
an angular application only scan the components template counterpart for every component scss file: | ||
```js | ||
purgecss({ | ||
contentFunction: (sourceInputFileName: string) => { | ||
if (/component\.scss$/.test(sourceInputFileName)) | ||
return [sourceInputFileName.replace(/scss$/, 'html')] | ||
else | ||
return ['./src/**/*.html'] | ||
}, | ||
}) | ||
``` | ||
### `extractors` | ||
@@ -53,12 +66,45 @@ Type: `Array<Object>` | ||
### `whitelist` | ||
Type: `Array<string>` | ||
### `safelist` | ||
You can whitelist selectors to stop Purgecss from removing them from your CSS. This can be accomplished with the options whitelist and whitelistPatterns. | ||
You can indicate which selectors are safe to leave in the final CSS. This can be accomplished with the option `safelist`. | ||
### `whitelistPatterns` | ||
Type: `Array<RegExp>` | ||
Two forms are available for this option. | ||
You can whitelist selectors based on a regular expression with whitelistPatterns. | ||
```ts | ||
safelist: ['random', 'yep', 'button', /^nav-/] | ||
``` | ||
In this form, safelist is an array that can take a string or a regex. | ||
The _complex_ form is: | ||
```ts | ||
safelist: { | ||
standard: ['random', 'yep', 'button', /^nav-/], | ||
deep: [], | ||
greedy: [], | ||
keyframes: [], | ||
variables: [] | ||
} | ||
``` | ||
### `blocklist` | ||
Blocklist will block the CSS selectors from appearing in the final output CSS. The selectors will be removed even when they are seen as used by PurgeCSS. | ||
```ts | ||
blocklist: ['usedClass', /^nav-/] | ||
``` | ||
Even if nav-links and usedClass are found by an extractor, they will be removed. | ||
### `skippedContentGlobs` | ||
If you provide globs for the `content` parameter, you can use this option to exclude certain files or folders that would otherwise be scanned. Pass an array of globs matching items that should be excluded. (Note: this option has no effect if `content` is not globs.) | ||
```ts | ||
skippedContentGlobs: ['node_modules/**', 'components/**'] | ||
``` | ||
Here, PurgeCSS will not scan anything in the "node_modules" and "components" folders. | ||
### `rejected` | ||
@@ -65,0 +111,0 @@ Type: `boolean` |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
12623
163
140
1
1
5
1
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcommander@9.5.0(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addednanoid@3.3.8(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.5.1(transitive)
+ Addedpurgecss@5.0.0(transitive)
+ Addedsource-map-js@1.2.1(transitive)
- Removedpostcss@7.0.26
- Removedansi-styles@3.2.1(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removedcommander@5.1.0(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedglob@7.2.3(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedpostcss@7.0.267.0.32(transitive)
- Removedpurgecss@2.3.0(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsupports-color@5.5.06.1.0(transitive)
Updatedpurgecss@^5.0.0