Giter Site home page Giter Site logo

americanexpress / purgecss-loader Goto Github PK

View Code? Open in Web Editor NEW
22.0 20.0 4.0 1.18 MB

✨ A Webpack loader to strip unused selectors from your CSS

License: Apache License 2.0

JavaScript 83.56% CSS 8.07% SCSS 8.37%
webpack-loader purgecss css optimization strip-unused-selectors css-modules one-app

purgecss-loader's Introduction

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 [email protected]

📖 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.

purgecss-loader's People

Contributors

10xlacroixdrinker avatar anescobar1991 avatar benmclees avatar dependabot[bot] avatar dogpatch626 avatar infoxicator avatar jamessingleton avatar jsmartfo avatar nellyk avatar oneamexbot avatar tklever avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

purgecss-loader's Issues

Dependency on vulnerable version of postcss

🐞 Bug Report

Describe the bug

postcss has a vulnerability for v7.0.32:
GHSA-566m-qj78-rww5

This is brought in by the [email protected] dep, which is pinning to an exact version rather than using semver.

"dependencies": {
    "commander": "^5.0.0",
    "glob": "^7.0.0",
    "postcss": "7.0.32",
    "postcss-selector-parser": "^6.0.2"
  },

Expected behavior

Dependencies should not have vulnerabilities

Reporting a vulnerability

Hello!

I hope you are doing well!

We are a security research team. Our tool automatically detected a vulnerability in this repository. We want to disclose it responsibly. GitHub has a feature called Private vulnerability reporting, which enables security research to privately disclose a vulnerability. Unfortunately, it is not enabled for this repository.

Can you enable it, so that we can report it?

Thanks in advance!

PS: you can read about how to enable private vulnerability reporting here: https://docs.github.com/en/code-security/security-advisories/repository-security-advisories/configuring-private-vulnerability-reporting-for-a-repository

add ability to whitelist selectors

Currently we do not have an option to whitelist certain selectors if you do not want them removed by PurgeCSS using this library.
This feature would be to add support for whitelisting selectors.

PurgeCSS supports whitelisting https://purgecss.com/whitelisting.html.

Through these three options:

  • Using specific selectors:
    whitelist: ['random', 'yep', 'button']
  • Using a regular expression:
whitelistPatterns: [/red$/],
whitelistPatternsChildren: [/blue$/]
  • In the CSS directly by adding this line to your css file.
    /* purgecss ignore */

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.