-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathoptimize.sh
More file actions
executable file
·31 lines (24 loc) · 969 Bytes
/
optimize.sh
File metadata and controls
executable file
·31 lines (24 loc) · 969 Bytes
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
#!/bin/bash
BUILD_TARGET_DIRECTORY=$1
# Compile any SCSS content in CSS files
find "$BUILD_TARGET_DIRECTORY/assets/css/" -name "*.css" | while read -r file;
do
echo "[Builder] Compressing CSS/SCSS file $file"
mv "$file" "$file".scss # sass can only convert .scss files, create a temp file
if ! npx sass "$file".scss "$file" --style=compressed --no-source-map;
then
exit_with_error "[Builder] Filed to compress CSS file '$file', exiting."
fi
rm "$file".scss # Delete the temp file
done || exit 1
# Compile any JS files
find "$BUILD_TARGET_DIRECTORY/assets/js/" -type f -name "*.js" ! -name "*.min.js" | while read -r file;
do
echo "[Builder] Converting JS file $file"
mv "$file" "$file".temp # temp file as we can't overwrite open file
if ! npx terser "$file".temp -o "$file" --compress --mangle;
then
exit_with_error "[Builder] Filed to compress JS file '$file', exiting."
fi
rm "$file".temp # Delete the temp file
done || exit 1