-
Notifications
You must be signed in to change notification settings - Fork 0
/
minify
executable file
·34 lines (29 loc) · 1016 Bytes
/
minify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
# Function to minify HTML files
minify_html() {
html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true "$1" -o "$1"
}
# Function to minify CSS files
minify_css() {
uglifycss "$1" >"$1.tmp" && mv "$1.tmp" "$1"
}
# Function to minify JS files
minify_js() {
uglifyjs --no-annotations "$1" -o "$1" -c -m
}
# Store file paths in an array
mapfile -t html_files < <(find ./dist -type f -name "*.html")
mapfile -t css_files < <(find ./dist -type f -name "*.css")
mapfile -t js_files < <(find ./dist -type f -name "*.js")
# Loop over HTML files and minify them
for file in "${html_files[@]}"; do
minify_html "$file"
done
# Loop over CSS files and minify them
for file in "${css_files[@]}"; do
minify_html "$file"
done
# Loop over JS files and minify them
for file in "${js_files[@]}"; do
minify_html "$file"
done