This commit is contained in:
2025-12-05 09:15:15 +01:00
commit 8837c20d66
1752 changed files with 1123339 additions and 0 deletions

139
node_modules/@fullhuman/postcss-purgecss/README.md generated vendored Normal file
View File

@@ -0,0 +1,139 @@
# PostCSS Purgecss
![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)
[PostCSS] plugin for PurgeCSS.
[PostCSS]: https://github.com/postcss/postcss
## Installation
```
npm i -D @fullhuman/postcss-purgecss postcss
```
## Usage
```js
const purgecss = require('@fullhuman/postcss-purgecss')
postcss([
purgecss({
content: ['./src/**/*.html']
})
])
```
See [PostCSS] docs for examples for your environment.
## 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).
### `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`
Type: `Array<Object>`
Purgecss can be adapted to suit your needs. If you notice a lot of unused CSS is not being removed, you might want to use a custom extractor.
More information about extractors [here](https://www.purgecss.com/extractors.html).
### `safelist`
You can indicate which selectors are safe to leave in the final CSS. This can be accomplished with the option `safelist`.
Two forms are available for this option.
```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`
Type: `boolean`
Default value: `false`
If true, purged selectors will be captured and rendered as PostCSS messages.
Use with a PostCSS reporter plugin like [`postcss-reporter`](https://github.com/postcss/postcss-reporter)
to print the purged selectors to the console as they are processed.
### `keyframes`
Type: `boolean`
Default value: `false`
If you are using a CSS animation library such as animate.css, you can remove unused keyframes by setting the keyframes option to true.
#### `fontFace`
Type: `boolean`
Default value: `false`
If there are any unused @font-face rules in your css, you can remove them by setting the fontFace option to true.
## Contributing
Please read [CONTRIBUTING.md](./../../CONTRIBUTING.md) for details on our code of
conduct, and the process for submitting pull requests to us.
## Versioning
postcss-purgecss use [SemVer](http://semver.org/) for versioning.
## License
This project is licensed under the MIT License - see the [LICENSE](./../../LICENSE) file
for details.

View File

@@ -0,0 +1,164 @@
/**
* 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
*/
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
*/
declare type ExtractorFunction<T = string> = (content: T) => ExtractorResult;
/**
* @public
*/
declare type ExtractorResult = ExtractorResultDetailed | string[];
/**
* @public
*/
declare interface ExtractorResultDetailed {
attributes: {
names: string[];
values: string[];
};
classes: string[];
ids: string[];
tags: string[];
undetermined: string[];
}
/**
* @public
*/
declare interface Extractors {
extensions: string[];
extractor: ExtractorFunction;
}
/**
* PostCSS Plugin for PurgeCSS
*
* @param opts - PurgeCSS Options
* @returns the postCSS plugin
*
* @public
*/
declare const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions>;
export default purgeCSSPlugin;
/**
* @public
*/
declare interface RawContent<T = string> {
extension: string;
raw: T;
}
/**
* @public
*/
declare interface RawCSS {
raw: string;
name?: string;
}
/**
* @public
*/
declare type StringRegExpArray = Array<RegExp | string>;
/**
* {@inheritDoc purgecss#UserDefinedOptions}
*
* @public
*/
export declare interface UserDefinedOptions extends Omit<UserDefinedOptions_2, "content" | "css"> {
content?: UserDefinedOptions_2["content"];
contentFunction?: (sourceFile: string) => Array<string | RawContent>;
}
/**
* Options used by PurgeCSS to remove unused CSS
*
* @public
*/
declare interface UserDefinedOptions_2 {
/** {@inheritDoc Options.content} */
content: Array<string | RawContent>;
/** {@inheritDoc Options.css} */
css: Array<string | RawCSS>;
/** {@inheritDoc Options.defaultExtractor} */
defaultExtractor?: ExtractorFunction;
/** {@inheritDoc Options.extractors} */
extractors?: Array<Extractors>;
/** {@inheritDoc Options.fontFace} */
fontFace?: boolean;
/** {@inheritDoc Options.keyframes} */
keyframes?: boolean;
/** {@inheritDoc Options.output} */
output?: string;
/** {@inheritDoc Options.rejected} */
rejected?: boolean;
/** {@inheritDoc Options.rejectedCss} */
rejectedCss?: boolean;
/** {@inheritDoc Options.sourceMap } */
sourceMap?: boolean | (postcss.SourceMapOptions & { to?: string });
/** {@inheritDoc Options.stdin} */
stdin?: boolean;
/** {@inheritDoc Options.stdout} */
stdout?: boolean;
/** {@inheritDoc Options.variables} */
variables?: boolean;
/** {@inheritDoc Options.safelist} */
safelist?: UserDefinedSafelist;
/** {@inheritDoc Options.blocklist} */
blocklist?: StringRegExpArray;
/** {@inheritDoc Options.skippedContentGlobs} */
skippedContentGlobs?: Array<string>;
/** {@inheritDoc Options.dynamicAttributes} */
dynamicAttributes?: string[];
}
/**
* @public
*/
declare type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
export { }

View File

@@ -0,0 +1 @@
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};

View File

@@ -0,0 +1 @@
"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;

42
node_modules/@fullhuman/postcss-purgecss/package.json generated vendored Normal file
View File

@@ -0,0 +1,42 @@
{
"name": "@fullhuman/postcss-purgecss",
"version": "5.0.0",
"description": "PostCSS plugin for PurgeCSS",
"author": "FoundrySH <no-reply@foundry.sh>",
"homepage": "https://purgecss.com",
"license": "MIT",
"main": "lib/postcss-purgecss.js",
"module": "lib/postcss-purgecss.esm.js",
"types": "lib/postcss-purgecss.d.ts",
"directories": {
"lib": "lib",
"test": "__tests__"
},
"files": [
"lib"
],
"repository": {
"type": "git",
"url": "git+https://github.com/FullHuman/purgecss.git"
},
"scripts": {
"build": "ts-node build.ts",
"test": "jest"
},
"bugs": {
"url": "https://github.com/FullHuman/purgecss/issues"
},
"dependencies": {
"purgecss": "^5.0.0"
},
"devDependencies": {
"postcss": "^8.4.4"
},
"peerDependencies": {
"postcss": "^8.0.0"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}