@@ -14,6 +14,10 @@ const path = require('path');
14
14
const PostCssAutoprefixerPlugin = require ( 'autoprefixer' ) ;
15
15
const PostCssRTLCSS = require ( 'postcss-rtlcss' ) ;
16
16
17
+ // Reduce CSS file size by ~70%
18
+ const { PurgeCSSPlugin } = require ( 'purgecss-webpack-plugin' ) ;
19
+ const glob = require ( 'glob' ) ;
20
+
17
21
const HtmlWebpackNewRelicPlugin = require ( '../lib/plugins/html-webpack-new-relic-plugin' ) ;
18
22
const commonConfig = require ( './webpack.common.config' ) ;
19
23
const presets = require ( '../lib/presets' ) ;
@@ -23,6 +27,10 @@ dotenv.config({
23
27
path : path . resolve ( process . cwd ( ) , '.env' ) ,
24
28
} ) ;
25
29
30
+ const PATHS = {
31
+ src : path . join ( __dirname , 'src' ) ,
32
+ } ;
33
+
26
34
const extraPlugins = [ ] ;
27
35
if ( process . env . ENABLE_NEW_RELIC !== 'false' ) {
28
36
// Enable NewRelic logging only if the account ID is properly defined
@@ -183,6 +191,13 @@ module.exports = merge(commonConfig, {
183
191
new MiniCssExtractPlugin ( {
184
192
filename : '[name].[chunkhash].css' ,
185
193
} ) ,
194
+
195
+ // The recommend usage by official docs
196
+ // https://purgecss.com/getting-started.html
197
+ new PurgeCSSPlugin ( {
198
+ paths : glob . sync ( `${ PATHS . src } /**/*` , { nodir : true } ) ,
199
+ } ) ,
200
+
186
201
// Generates an HTML file in the output directory.
187
202
new HtmlWebpackPlugin ( {
188
203
inject : true , // Appends script tags linking to the webpack bundles at the end of the body
0 commit comments