Skip to content

Commit f1e7413

Browse files
committed
Adds whitelister utility & configuration for whitelisting css libraries
1 parent 7e09f85 commit f1e7413

File tree

4 files changed

+6363
-0
lines changed

4 files changed

+6363
-0
lines changed

build/webpack.prod.conf.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const ManifestPlugin = require('webpack-manifest-plugin')
1515
const PurgecssPlugin = require('purgecss-webpack-plugin')
1616
const glob = require('glob-all')
1717

18+
// whitelister for purgecss to help with libraries
19+
const whitelister = require('purgecss-whitelister')
20+
1821
// Custom PurgeCSS extractor for Tailwind that allows special characters in
1922
// class names.
2023
//
@@ -74,6 +77,8 @@ const webpackConfig = merge(baseWebpackConfig, {
7477
path.join(__dirname, './../**/*.vue'),
7578
path.join(__dirname, './../src/**/*.js')
7679
]),
80+
whitelist: whitelister(config.build.purgecssWhitelist),
81+
whitelistPatterns: config.build.purgecssWhitelistPatterns,
7782
extractors: [
7883
{
7984
extractor: TailwindExtractor,

config/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ module.exports = {
5151
assetsSubDirectory: 'static',
5252
assetsPublicPath: '/',
5353

54+
// Whitelist selectors to stop purgecss from removing them from your CSS
55+
// You can pass in whole stylesheets to whitelist everything from thirdparty libs
56+
// Accepts string paths, array of strings, globby strings, or array of globby strings:
57+
// ['./node_modules/lib1/*.css', './node_modules/lib2/*.scss']
58+
purgecssWhitelist: [],
59+
60+
// Whitelist based on a regular expression.
61+
// Ex: [/red$/] (selectors ending in 'red' will remain)
62+
// https://www.purgecss.com/whitelisting
63+
purgecssWhitelistPatterns: [],
64+
5465
/**
5566
* Source Maps
5667
*/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"postcss-loader": "^2.0.8",
5151
"postcss-url": "^7.2.1",
5252
"purgecss-webpack-plugin": "^0.22.0",
53+
"purgecss-whitelister": "^2.1.0",
5354
"rimraf": "^2.6.0",
5455
"sane": "^2.5.0",
5556
"semver": "^5.3.0",

0 commit comments

Comments
 (0)