Skip to content

Commit

Permalink
feat: use postcss plugin instead of webpack plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ghassanmas committed Mar 14, 2023
1 parent cdb85a8 commit 5c9314c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
17 changes: 5 additions & 12 deletions config/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const PostCssRTLCSS = require('postcss-rtlcss');
const PostCssCustomMediaCSS = require('postcss-custom-media');

// Reduce CSS file size by ~70%
const { PurgeCSSPlugin } = require('purgecss-webpack-plugin');
const glob = require('glob');
const purgecss = require('@fullhuman/postcss-purgecss');

const HtmlWebpackNewRelicPlugin = require('../lib/plugins/html-webpack-new-relic-plugin');
const commonConfig = require('./webpack.common.config');
Expand All @@ -30,10 +29,6 @@ dotenv.config({
path: path.resolve(process.cwd(), '.env'),
});

const PATHS = {
src: path.join(__dirname, 'src'),
};

const extraPlugins = [];
if (process.env.ENABLE_NEW_RELIC !== 'false') {
// Enable NewRelic logging only if the account ID is properly defined
Expand Down Expand Up @@ -116,6 +111,10 @@ module.exports = merge(commonConfig, {
PostCssRTLCSS(),
CssNano(),
PostCssCustomMediaCSS(),
purgecss({
content: ['./**/*.html', './**/*.js', './**/*.jsx'],
}),

],
},
},
Expand Down Expand Up @@ -196,12 +195,6 @@ module.exports = merge(commonConfig, {
filename: '[name].[chunkhash].css',
}),

// The recommend usage by official docs
// https://purgecss.com/getting-started.html
new PurgeCSSPlugin({
paths: glob.sync(`${PATHS.src}/**/*`, { nodir: true }),
}),

// Generates an HTML file in the output directory.
new HtmlWebpackPlugin({
inject: true, // Appends script tags linking to the webpack bundles at the end of the body
Expand Down
27 changes: 21 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"webpack-cli": "4.10.0",
"webpack-dev-server": "4.7.3",
"webpack-merge": "5.8.0",
"purgecss-webpack-plugin": "^5.0.0"
"@fullhuman/postcss-purgecss": "^5.0.0"
},
"devDependencies": {
"@babel/preset-typescript": "^7.18.6",
Expand Down

0 comments on commit 5c9314c

Please sign in to comment.