Skip to content

Commit

Permalink
✨ Add postcss-prune-var dependency to remove unused variables from …
Browse files Browse the repository at this point in the history
…CSS files
  • Loading branch information
skerit committed Mar 3, 2024
1 parent 0fdf467 commit 81ed744
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Add the abstract `Meta` field class: these should be used for fields that are not directly stored in the database
* Add association aliases as a meta field to model schemas
* Add `should_add_exports()` SCSS function
* Add `postcss-prune-var` dependency to remove unused variables from CSS files

## 1.4.0-alpha.3 (2024-02-25)

Expand Down
14 changes: 13 additions & 1 deletion lib/core/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let publicDirs = alchemy.shared('public.directories', new Deck()),
regenerator_runtime,
sass_functions,
babel_polyfill,
postcss_prune,
babel_preset,
babel_async,
autoprefixer,
Expand Down Expand Up @@ -93,6 +94,7 @@ if (alchemy.settings.frontend.stylesheet.enable_scss) {
if (alchemy.settings.frontend.stylesheet.enable_post !== false) {
postcss = alchemy.use('postcss');
autoprefixer = alchemy.use('autoprefixer');
postcss_prune = alchemy.use('postcss-prune-var')();
}

if (alchemy.settings.frontend.javascript.enable_babel) {
Expand Down Expand Up @@ -1009,7 +1011,16 @@ Alchemy.setMethod(function findAssetPath(assetFile, directories, callback) {
* @param {Function} callback
*/
function doPostCss(css, options, callback) {
postcss([autoprefixer]).process(css, {from: undefined}).then(function gotCssResult(result) {

let postcss_config = [
autoprefixer
];

if (options.prune !== false) {
postcss_config.push(postcss_prune);
}

postcss(postcss_config).process(css, {from: undefined}).then(function gotCssResult(result) {

if (options?.post_css_only) {
return callback(null, result);
Expand Down Expand Up @@ -1486,6 +1497,7 @@ Alchemy.setMethod(async function extractCSSExports(css_path) {
let result = await findStylesheet(css_path, {
post_css_only: true,
add_exports: true,
prune: false,
compile: true
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"mongodb" : "~6.1.0",
"ncp" : "~2.0.0",
"postcss" : "~8.4.31",
"postcss-prune-var": "~1.1.2",
"protoblast" : "~0.9.1",
"semver" : "~7.5.4",
"socket.io" : "~4.7.2",
Expand Down

0 comments on commit 81ed744

Please sign in to comment.