purgecss-webpack-plugin

  • Version 9.1.0
  • Published
  • 75.6 kB
  • 1 dependency
  • MIT license

Install

npm i purgecss-webpack-plugin
yarn add purgecss-webpack-plugin
pnpm add purgecss-webpack-plugin

Overview

PurgeCSS plugin for webpack and Rspack - Remove unused css

Index

Classes

class PurgeCSSPlugin

class PurgeCSSPlugin {}
  • Modifiers

    • @public

constructor

constructor(options: UserDefinedOptions);

    property options

    options: UserDefinedOptions;

      property purgedStats

      purgedStats: PurgedStats;

        method apply

        apply: (compiler: CompilerLike) => void;
        • Apply the plugin to a webpack or Rspack compiler

          Parameter compiler

          compiler of webpack or Rspack

        method initializePlugin

        initializePlugin: (compilationLike: CompilationLike) => void;
        • Purge the CSS assets of a compilation of webpack or Rspack

          Parameter compilationLike

          compilation of webpack or Rspack

        method runPluginHook

        runPluginHook: (
        compilationLike: CompilationLike,
        entryPaths: string[]
        ) => Promise<void>;
        • Purge the CSS assets of a compilation

          Parameter compilationLike

          compilation of webpack or Rspack

          Parameter entryPaths

          content files

        Interfaces

        interface CompilerLike

        interface CompilerLike {}
        • Compiler of webpack or Rspack, the part of it the plugin is applied to. The types of the plugin do not depend on webpack, which Rspack projects don't install.

          Modifiers

          • @public

        property hooks

        hooks: {
        compilation: {
        tap(
        name: string,
        callback: (compilation: CompilationLike) => void
        ): void;
        };
        };

          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

                            Type Aliases

                            type BlocklistFunction

                            type BlocklistFunction = () => StringRegExpArray;
                            • Modifiers

                              • @public

                            type CompilationLike

                            type CompilationLike = object;
                            • Compilation of webpack or Rspack

                              Modifiers

                              • @public

                            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 PathFunction

                            type PathFunction = () => string[];
                            • Modifiers

                              • @public

                            type PurgedStats

                            type PurgedStats = {
                            [index: string]: string[];
                            };
                            • Modifiers

                              • @public

                            type SafelistFunction

                            type SafelistFunction = () => ComplexSafelist;
                            • 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 UserDefinedOptions

                            type UserDefinedOptions = Omit<
                            PurgeCSSUserDefinedOptions,
                            'css' | 'content' | 'safelist' | 'blocklist' | 'sourceMap'
                            > & {
                            paths: string[] | PathFunction;
                            moduleExtensions?: string[];
                            verbose?: boolean;
                            safelist?: PurgeCSSUserDefinedOptions['safelist'] | SafelistFunction;
                            blocklist?: PurgeCSSUserDefinedOptions['blocklist'] | BlocklistFunction;
                            only?: string[];
                            };
                            • Modifiers

                              • @public

                            type UserDefinedSafelist

                            type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
                            • Modifiers

                              • @public

                            Package Files (1)

                            Dependencies (1)

                            Dev Dependencies (5)

                            Peer Dependencies (2)

                            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/purgecss-webpack-plugin.

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