Add and configure PurgeCSS

References #34
This commit is contained in:
Oliver Davies 2020-03-16 08:56:30 +00:00
parent c4438f7e86
commit 81ceb75765
5 changed files with 78 additions and 1 deletions

3
.gitignore vendored
View file

@ -6,7 +6,8 @@
!/netlify.toml
!/package*.json
!/postcss.config.js
!/tailwind.config.js
!/purgecss.config.js
!/public/images/**
!/public/index.html
!/tailwind.config.js
!/webpack.config.js

58
package-lock.json generated
View file

@ -4381,6 +4381,33 @@
"path-is-absolute": "^1.0.0"
}
},
"glob-all": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/glob-all/-/glob-all-3.1.0.tgz",
"integrity": "sha1-iRPd+17hrHgSZWJBsD1SF8ZLAqs=",
"dev": true,
"requires": {
"glob": "^7.0.5",
"yargs": "~1.2.6"
},
"dependencies": {
"minimist": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.1.0.tgz",
"integrity": "sha1-md9lelJXTCHJBXSX33QnkLK0wN4=",
"dev": true
},
"yargs": {
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-1.2.6.tgz",
"integrity": "sha1-nHtKgv1dWVsr8Xq23MQxNUMv40s=",
"dev": true,
"requires": {
"minimist": "^0.1.0"
}
}
}
},
"glob-parent": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-3.1.0.tgz",
@ -6944,6 +6971,37 @@
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==",
"dev": true
},
"purgecss": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/purgecss/-/purgecss-2.1.0.tgz",
"integrity": "sha512-QnXhowNjeWo9vNnGES2LVzDXdRR/8EvG/O03m4bYOWfAX0ShmG/Pmj7brVtVBy2eaaRAmNy23L+GBc4SpDFUeQ==",
"dev": true,
"requires": {
"commander": "^4.0.0",
"glob": "^7.0.0",
"postcss": "7.0.27",
"postcss-selector-parser": "^6.0.2"
},
"dependencies": {
"commander": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz",
"integrity": "sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==",
"dev": true
}
}
},
"purgecss-webpack-plugin": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/purgecss-webpack-plugin/-/purgecss-webpack-plugin-2.1.0.tgz",
"integrity": "sha512-zbcGmlQ/RwI3tIFegZKE0KhP/G9I+IUbEgQkwEF/xkj4MBLODgy5Vg3sV/B1iAKD2jAoyfWYH+TjPd5nVgGslw==",
"dev": true,
"requires": {
"purgecss": "^2.1.0",
"webpack": "^4.41.2",
"webpack-sources": "^1.4.3"
}
},
"q": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",

View file

@ -9,7 +9,9 @@
},
"devDependencies": {
"@symfony/webpack-encore": "^0.28.3",
"glob-all": "^3.1.0",
"postcss-loader": "^3.0.0",
"purgecss-webpack-plugin": "^2.1.0",
"vue-template-compiler": "^2.6.11"
},
"dependencies": {

10
purgecss.config.js Normal file
View file

@ -0,0 +1,10 @@
let glob = require('glob-all')
module.exports = {
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || [],
paths: () => glob.sync([
'public/index.html'
]),
whitelist: [],
whitelistPatterns: []
}

View file

@ -1,4 +1,6 @@
let Encore = require('@symfony/webpack-encore')
let purgecssConfig = require('./purgecss.config')
let PurgecssPlugin = require('purgecss-webpack-plugin')
Encore
.disableSingleRuntimeChunk()
@ -11,4 +13,8 @@ Encore
loaderRule.test = /\.(css|p(ost)?css)$/
})
if (Encore.isProduction()) {
Encore.addPlugin(new PurgecssPlugin(purgecssConfig))
}
module.exports = Encore.getWebpackConfig()