├── .editorconfig ├── .github └── workflows │ └── run-tests.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── __test__ ├── __snapshots__ │ └── createConfig.test.js.snap └── createConfig.test.js ├── package.json └── src ├── createConfig.js ├── defaultConfig.js └── index.js /.editorconfig: -------------------------------------------------------------------------------- 1 | ; This file is for unifying the coding style for different editors and IDEs. 2 | ; More information at http://editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | indent_size = 4 9 | indent_style = space 10 | end_of_line = lf 11 | insert_final_newline = true 12 | trim_trailing_whitespace = true 13 | 14 | [{package.json}] 15 | indent_size = 2 16 | 17 | [*.md] 18 | trim_trailing_whitespace = false 19 | -------------------------------------------------------------------------------- /.github/workflows/run-tests.yml: -------------------------------------------------------------------------------- 1 | name: run-tests 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - name: Use Node.js 11 | uses: actions/setup-node@v1 12 | with: 13 | node-version: "12.x" 14 | - run: yarn 15 | - run: yarn test 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | yarn-error.log 4 | yarn.lock 5 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `postcss-purgecss-laravel` will be documented in this file. 4 | 5 | ## 2.0.0 6 | - Upgrade to Purgecss 3 7 | 8 | ## 1.0.0 9 | - Initial release 10 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Spatie bvba 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [](https://supportukrainenow.org) 3 | 4 | # `postcss-purgecss` wrapper with sensible defaults for Laravel apps 5 | 6 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 7 | [![Latest Version on NPM](https://img.shields.io/npm/v/postcss-purgecss-laravel.svg?style=flat-square)](https://npmjs.com/package/postcss-purgecss-laravel) 8 | [![npm](https://img.shields.io/npm/dt/postcss-purgecss-laravel.svg?style=flat-square)](https://www.npmjs.com/package/postcss-purgecss-laravel) 9 | 10 | A simple wrapper around `postcss-purgecss` with sensible defaults for Laravel apps. 11 | 12 | ```js 13 | // postcss.config.js 14 | 15 | module.exports = { 16 | plugins: [ 17 | require('postcss-purgecss-laravel')({ 18 | safelist: [/hljs/], 19 | extend: { 20 | content: [path.join(__dirname, 'vendor/spatie/menu/**/*.php')], 21 | }, 22 | }); 23 | ], 24 | }; 25 | ``` 26 | 27 | ## Support us 28 | 29 | [](https://spatie.be/github-ad-click/postcss-purgecss-laravel) 30 | 31 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). 32 | 33 | We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). 34 | 35 | ## Installation 36 | 37 | You can install the package with yarn or npm: 38 | 39 | ```bash 40 | yarn add postcss-purgecss-laravel --dev 41 | ``` 42 | 43 | ```bash 44 | npm install postcss-purgecss-laravel --save-dev 45 | ``` 46 | 47 | ## Usage 48 | 49 | Register the PostCSS plugin. 50 | 51 | ```js 52 | // postcss.config.js 53 | 54 | module.exports = { 55 | plugins: [ 56 | require('postcss-purgecss-laravel')(/* ... */), 57 | ] 58 | } 59 | ``` 60 | 61 | All options passed to the plugin get passed down to PurgeCSS. Refer to the [PurgeCSS docs](https://purgecss.com/configuration.html#configuration-file) for an overview of the available options. 62 | 63 | ```js 64 | // postcss.config.js 65 | 66 | module.exports = { 67 | plugins: [ 68 | require('postcss-purgecss-laravel')({ 69 | safelist: [/hljs/], 70 | }), 71 | ], 72 | }; 73 | ``` 74 | 75 | Options will _override_ the default options this package provides. If you'd rather _extend_ the options, place them in the `extend` option. 76 | 77 | ```js 78 | // postcss.config.js 79 | 80 | module.exports = { 81 | plugins: [ 82 | require('postcss-purgecss-laravel')({ 83 | extend: { 84 | safelist: [/hljs/], 85 | }, 86 | }), 87 | ], 88 | }; 89 | ``` 90 | 91 | In the above example, the `/hljs/` pattern will be _added_ to the `safelist`, instead of overriding the default `safelist` option. 92 | 93 | These are the defaults this package provides: 94 | 95 | ```js 96 | const defaultConfig = { 97 | content: [ 98 | "app/**/*.php", 99 | "resources/**/*.html", 100 | "resources/**/*.js", 101 | "resources/**/*.jsx", 102 | "resources/**/*.ts", 103 | "resources/**/*.tsx", 104 | "resources/**/*.php", 105 | "resources/**/*.vue", 106 | "resources/**/*.twig", 107 | ], 108 | defaultExtractor: (content) => content.match(/[\w-/.:]+(? { 4 | expect(createConfig({})).toMatchSnapshot(); 5 | }); 6 | 7 | test("it can override the default config", () => { 8 | const config = { 9 | content: ["resource/js/**/*.js"], 10 | }; 11 | 12 | expect(createConfig(config)).toMatchSnapshot(); 13 | }); 14 | 15 | test("it can extend the default config", () => { 16 | const config = { 17 | extend: { 18 | content: ["vendor/spatie/menu/**/*.php"], 19 | }, 20 | }; 21 | 22 | expect(createConfig(config)).toMatchSnapshot(); 23 | }); 24 | 25 | test("it can extend and override the default config", () => { 26 | const config = { 27 | safelist: [], 28 | extend: { 29 | content: ["vendor/spatie/menu/**/*.php"], 30 | }, 31 | }; 32 | 33 | expect(createConfig(config)).toMatchSnapshot(); 34 | }); 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-purgecss-laravel", 3 | "version": "2.0.0", 4 | "description": "postcss-purgecss wrapper with sensible defaults for Laravel apps", 5 | "main": "src/index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/spatie/postcss-purgecss-laravel.git" 9 | }, 10 | "keywords": [ 11 | "spatie" 12 | ], 13 | "author": "Sebastian De Deyne", 14 | "license": "MIT", 15 | "bugs": { 16 | "url": "https://github.com/spatie/postcss-purgecss-laravel/issues" 17 | }, 18 | "homepage": "https://github.com/spatie/postcss-purgecss-laravel", 19 | "scripts": { 20 | "format": "prettier --write \"**/*.js\"", 21 | "test": "jest" 22 | }, 23 | "dependencies": { 24 | "@fullhuman/postcss-purgecss": "^3.0.0" 25 | }, 26 | "devDependencies": { 27 | "jest": "^25.4.0", 28 | "prettier": "^2.0.5" 29 | }, 30 | "engines": { 31 | "node": ">=12.0.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/createConfig.js: -------------------------------------------------------------------------------- 1 | const defaultConfig = require("./defaultConfig"); 2 | 3 | module.exports = function createConfig(config) { 4 | const { extend = {}, ...overrides } = config; 5 | 6 | const overriddenConfig = Object.assign({}, defaultConfig, overrides); 7 | 8 | Object.entries(extend).forEach(([key, value]) => { 9 | overriddenConfig[key] = Array.isArray(overriddenConfig[key]) 10 | ? overriddenConfig[key].concat(value) 11 | : value; 12 | }); 13 | 14 | return overriddenConfig; 15 | }; 16 | -------------------------------------------------------------------------------- /src/defaultConfig.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | content: [ 3 | "app/**/*.php", 4 | "resources/**/*.html", 5 | "resources/**/*.js", 6 | "resources/**/*.jsx", 7 | "resources/**/*.ts", 8 | "resources/**/*.tsx", 9 | "resources/**/*.php", 10 | "resources/**/*.vue", 11 | "resources/**/*.twig", 12 | ], 13 | defaultExtractor: (content) => content.match(/[\w-/.:]+(? 4 | require("@fullhuman/postcss-purgecss")(createConfig(config)); 5 | --------------------------------------------------------------------------------