Skip to content

Commit

Permalink
Add Lightning CSS minifier (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
renelamo committed Mar 19, 2024
1 parent 24cb985 commit 17c2261
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Minifies JS and CSS files with Babel-Minify and CleanCSS
| overwrite | Overwrites the existing files with the minified version. Defaults to false. | false | false |
| maxdepth | Descend at most levels (a non-negative integer) levels of directories below the starting-points. | false | "" (empty) |
| js_engine | Specifies which of the supported packages minifies JS files. Supported packages: `babel`, `uglify-js` | false | babel |
| css_engine | Specifies which of the supported packages minifies CSS files. Supported packages: `lightning`, `clean-css` | false | lightning |

> With the addition of `maxdepth`, the action traverses by default into all subdirectories in a specified directory.
>
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ inputs:
description: "Specifies which of the supported packages minifies JS files."
required: false
default: "babel"
css_engine:
description: "Specifies which of the supported packages minifies CSS files."
required: false
default: "lightning"

runs:
using: "docker"
Expand Down
24 changes: 23 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ exec_minify_js () {
fi
}

exec_minify_css () {
: '
arguments:
1- input file
2- output file
returns the command needed to minify the css file
based on the requested CSS Engine in the
input `css_engine`
'
file=$1
out=$2

css_engine=$INPUT_CSS_ENGINE

if [[ $css_engine == "clean-css" ]]; then
npx cleancss -o $out $file
elif [[ $css_engine == "lightning" ]]; then
npx lightningcss --minify $file --output-file $out
fi
}

exec_minify_cmd () {
: '
arguments:
Expand All @@ -108,7 +130,7 @@ exec_minify_cmd () {
if [[ $file == *.js ]]; then
exec_minify_js $file $out
elif [[ $file == *.css ]]; then
npx cleancss -o $out $file
exec_minify_css $file $out
fi
}

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"dependencies": {
"uglify-js": "^3.10.0",
"babel-minify": "^0.5.1",
"clean-css-cli": "^4.3.0"
"clean-css-cli": "^4.3.0",
"lightningcss-cli": "^1.24.1"
},
"author": {
"name": "Nizar Mahmoud",
Expand Down

0 comments on commit 17c2261

Please sign in to comment.