@fullhuman/postcss-purgecss

  • Version 9.1.0
  • Published
  • 96.3 kB
  • 2 dependencies
  • MIT license

Install

npm i @fullhuman/postcss-purgecss
yarn add @fullhuman/postcss-purgecss
pnpm add @fullhuman/postcss-purgecss

Overview

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.

Index

Variables

variable purgeCSSPlugin

const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions>;
  • PostCSS Plugin for PurgeCSS

    Parameter opts

    PurgeCSS Options

    Returns

    the postCSS plugin

    Modifiers

    • @public

Interfaces

interface DependenciesOptions

interface DependenciesOptions {}
  • Options of the dependency messages of the content

    Modifiers

    • @public

property root

root?: string;
  • Root directory of the bundler, absolute or relative to the working directory: the content paths outside it get no dependency message.

interface ExtractorResultDetailed

interface ExtractorResultDetailed {}
  • Modifiers

    • @public

property attributes

attributes: {
names: string[];
values: string[];
};

    property classes

    classes: string[];

      property ids

      ids: string[];

        property tags

        tags: string[];

          property undetermined

          undetermined: string[];

            interface Extractors

            interface Extractors {}
            • Modifiers

              • @public

            property extensions

            extensions: string[];

              property extractor

              extractor: ExtractorFunction;

                interface PurgeCSSUserDefinedOptions

                interface PurgeCSSUserDefinedOptions {}
                • Options used by PurgeCSS to remove unused CSS

                  Modifiers

                  • @public

                property blocklist

                blocklist?: StringRegExpArray;

                property content

                content: Array<string | RawContent>;

                property css

                css: Array<string | RawCSS>;

                property defaultExtractor

                defaultExtractor?: ExtractorFunction;

                property dynamicAttributes

                dynamicAttributes?: StringRegExpArray;

                property extractors

                extractors?: Array<Extractors>;

                property fontFace

                fontFace?: boolean;

                property keyframes

                keyframes?: boolean;

                property output

                output?: string;

                property rejected

                rejected?: boolean;

                property rejectedCss

                rejectedCss?: boolean;

                property safelist

                safelist?: UserDefinedSafelist;

                property skippedContentGlobs

                skippedContentGlobs?: Array<string>;

                property sourceMap

                sourceMap?: boolean | (postcss.SourceMapOptions & { to?: string });

                property stdin

                stdin?: boolean;

                property stdout

                stdout?: boolean;

                property variables

                variables?: boolean;

                interface RawContent

                interface RawContent<T = string> {}
                • Modifiers

                  • @public

                property extension

                extension: string;

                  property raw

                  raw: T;

                    interface RawCSS

                    interface RawCSS {}
                    • Modifiers

                      • @public

                    property name

                    name?: string;
                    • name of the css, returned as the file of its result. It is used as the path of the css in source maps, like the path of a css file: the map sources are relative to the directory of sourceMap.to, which defaults to the name.

                    property raw

                    raw: string;
                    • css to purge

                    interface UserDefinedOptions

                    interface UserDefinedOptions
                    extends Omit<PurgeCSSUserDefinedOptions, 'content' | 'css'> {}

                    property content

                    content?: PurgeCSSUserDefinedOptions['content'];

                      property contentCache

                      contentCache?: boolean;
                      • Keep the selectors extracted from the content files between the CSS files and the runs of the plugin in the process: a content file is only read and extracted again when it changed. Set it to false to read and extract the content files for every CSS file.

                      property contentFunction

                      contentFunction?: (sourceFile: string) => Array<string | RawContent>;

                        property dependencies

                        dependencies?: boolean | DependenciesOptions;
                        • Add PostCSS dependency messages for the content files and globs, so that the dev servers (Vite, webpack and Rspack with postcss-loader, Next.js, Parcel) run the plugin again when the content changes. Set it to false to add no message, e.g. when a bundler rejects a path of the content.

                          Pass an object to set the root directory of the bundler: the paths outside it get no message. Under Turbopack (Next.js), which stops with an error for a path outside its root, the root defaults to the one Next.js infers (the outermost directory with a workspace marker or a lock file). Set it to the value of outputFileTracingRoot or turbopack.root when the Next.js config sets one of them.

                        Type Aliases

                        type ComplexSafelist

                        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?: StringRegExpArray;
                        /**
                        * You can safelist whole selectors if any part of that selector matches a
                        * pattern with `safelist.greedy`
                        *
                        * @example
                        *
                        * ```ts
                        * const purgecss = await new PurgeCSS().purge({
                        * content: [],
                        * css: [],
                        * safelist: {
                        * greedy: [/red$/]
                        * }
                        * })
                        * ```
                        *
                        * In this example, selectors such as `button.bg-red.nonexistent-class`
                        * will be left in the final CSS, even if `button` and `nonexistent-class`
                        * are not found.
                        *
                        */
                        greedy?: StringRegExpArray;
                        variables?: StringRegExpArray;
                        keyframes?: StringRegExpArray;
                        };
                        • Modifiers

                          • @public

                        type ExtractorFunction

                        type ExtractorFunction<T = string> = (content: T) => ExtractorResult;
                        • Modifiers

                          • @public

                        type ExtractorResult

                        type ExtractorResult = ExtractorResultDetailed | string[];
                        • Modifiers

                          • @public

                        type StringRegExpArray

                        type StringRegExpArray = Array<RegExp | string>;
                        • Strings and regular expressions an option is matched against. A string matches a value exactly, except a string written between slashes, like "/^btn-/" or "/^btn-/i", which is parsed as a regular expression. This form lets configuration files that cannot contain regular expressions, such as postcss.config.json, use patterns.

                          Modifiers

                          • @public

                        type UserDefinedSafelist

                        type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
                        • Modifiers

                          • @public

                        Package Files (1)

                        Dependencies (2)

                        Dev Dependencies (2)

                        Peer Dependencies (1)

                        Badge

                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@fullhuman/postcss-purgecss.

                        • Markdown
                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@fullhuman/postcss-purgecss)
                        • HTML
                          <a href="https://www.jsdocs.io/package/@fullhuman/postcss-purgecss"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>