Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/americanexpress/purgecss-loader
โจ A Webpack loader to strip unused selectors from your CSS
https://github.com/americanexpress/purgecss-loader
css css-modules one-app optimization purgecss strip-unused-selectors webpack-loader
Last synced: 18 days ago
JSON representation
โจ A Webpack loader to strip unused selectors from your CSS
- Host: GitHub
- URL: https://github.com/americanexpress/purgecss-loader
- Owner: americanexpress
- License: apache-2.0
- Created: 2018-05-04T16:02:04.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-11-06T15:05:58.000Z (about 1 year ago)
- Last Synced: 2024-04-14T13:05:35.368Z (7 months ago)
- Topics: css, css-modules, one-app, optimization, purgecss, strip-unused-selectors, webpack-loader
- Language: JavaScript
- Homepage:
- Size: 1.15 MB
- Stars: 22
- Watchers: 20
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
[One App is now InnerSource](https://github.com/americanexpress/one-app/issues/1393)
[![npm version](https://badge.fury.io/js/%40americanexpress%2Fpurgecss-loader.svg)](https://badge.fury.io/js/%40americanexpress%2Fpurgecss-loader)
> This [Webpack](https://github.com/webpack/webpack) loader uses [purgecss](https://github.com/FullHuman/purgecss)
to strip unused selectors from your CSS.## ๐ Table of Contents
* [Features](#-features)
* [Usage](#-usage)
* [API](#%EF%B8%8F-api)
* [License](#%EF%B8%8F-license)
* [Code Of Conduct](#%EF%B8%8F-code-of-conduct)
* [Contributing](#-contributing)## โจ 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:
```js
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`](https://github.com/webpack-contrib/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` |[glob]: https://github.com/isaacs/node-glob
[purgecss extractors]: https://www.purgecss.com/extractors.html
[options]: https://purgecss.com/configuration.html#options## ๐๏ธ License
Any contributions made under this project will be governed by the
[Apache License 2.0](./LICENSE.txt).## ๐ฃ๏ธ Code of Conduct
This project adheres to the [American Express Community Guidelines](./CODE_OF_CONDUCT.md).
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](https://cla-assistant.io/americanexpress/purgecss-loader).Please feel free to open pull requests and see [CONTRIBUTING.md](./CONTRIBUTING.md)
for commit formatting details.