diff --git a/.gitignore b/.gitignore index 2de5dc8..81dac0a 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/package-lock.json b/package-lock.json index 923ba7f..fd53037 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index f2b2a66..cd413d4 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/purgecss.config.js b/purgecss.config.js new file mode 100644 index 0000000..2585d3f --- /dev/null +++ b/purgecss.config.js @@ -0,0 +1,10 @@ +let glob = require('glob-all') + +module.exports = { + defaultExtractor: content => content.match(/[\w-/:]+(? glob.sync([ + 'public/index.html' + ]), + whitelist: [], + whitelistPatterns: [] +} diff --git a/webpack.config.js b/webpack.config.js index 1addd94..163e1e8 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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()