JSPM

@americanexpress/purgecss-loader

4.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 556
  • Score
    100M100P100Q96644F
  • License Apache-2.0

Webpack loader for removing unused CSS

Package Exports

  • @americanexpress/purgecss-loader
  • @americanexpress/purgecss-loader/loader.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@americanexpress/purgecss-loader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

purgecss-loader - One Amex

npm version Health Check

This Webpack loader uses purgecss to strip unused selectors from your CSS.

๐Ÿ‘ฉโ€๐Ÿ’ป Hiring ๐Ÿ‘จโ€๐Ÿ’ป

Want to get paid for your contributions to purgecss-loader? Send your resume to oneamex.careers@aexp.com

๐Ÿ“– Table of Contents

โœจ Features

  • Ability to remove CSS modules
  • Ability to remove plain CSS declarations
  • Reduce bundle size

๐Ÿคนโ€ Usage

npm install -D @americanexpress/purgecss-loader

๐ŸŽ›๏ธ API

Configure as follows:

module.exports = {
  entry: {...},
  output: {...},
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          {
            loader: 'css-loader',
            options: {
              modules: true,
              localIdentName: '[name]__[local]___[hash:base64:5]',
            },
          },
          {
            loader: '@americanexpress/purgecss-loader',
            options: {
              paths: [path.join(somePath, 'src/**/*.{js,jsx}')],
              safelist: [/:global$/],
            },
          },
        ],
      },
    ],
  },
}

You should use this with the css-loader as seen above. However, it is not required that you use CSS modules. That is in the example to express this loader's compatibility.

Options

Property Description Required
paths An array of file glob patterns true
extractors An array of purgecss extractors false
fontFace boolean (default: false) see options false
keyframes boolean (default: false) see options false
variables boolean (default: false) see options false
safelist UserDefinedSafelist see options false
blocklist StringRegExpArray see options false

๐Ÿ—๏ธ License

Any contributions made under this project will be governed by the Apache License 2.0.

๐Ÿ—ฃ๏ธ Code of Conduct

This project adheres to the American Express Community Guidelines. By participating, you are expected to honor these guidelines.

๐Ÿ† Contributing

We welcome Your interest in the American Express Open Source Community on Github. Any Contributor to any Open Source Project managed by the American Express Open Source Community must accept and sign an Agreement indicating agreement to the terms below. Except for the rights granted in this Agreement to American Express and to recipients of software distributed by American Express, You reserve all right, title, and interest, if any, in and to Your Contributions. Please fill out the Agreement.

Please feel free to open pull requests and see CONTRIBUTING.md for commit formatting details.