-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·65 lines (50 loc) · 1.41 KB
/
build.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh
# arguments:
# -l : first compile language grammars in directory
# -t : first compile transform grammars in directory
# -o : output directory
# -b : intermediate build directory
# -s : Elm source dir
# -O : optimize
static_dir="docs"
build_dir="build"
elm_dir="src"
optimize=false
while getopts ":o:b:s:O" opt; do
case $opt in
o)
static_dir=$OPTARG
;;
b)
build_dir=$OPTARG
;;
s)
elm_dir=$OPTARG
;;
O)
optimize=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Adapted from optimize.sh in the Elm tutorial
# (https://guide.elm-lang.org/optimization/asset_size.html)
elm="${elm_dir}/Main.elm"
js="${build_dir}/main.js"
min="${static_dir}/main.min.js"
echo "Compiling Elm to JS"
if [ $optimize = true ]
then
elm make --optimize --output=$js $elm || { exit 1; }
echo "Optimizing JS"
echo "Compiled size: $(cat $js | wc -c) bytes ($js)"
uglifyjs $js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | uglifyjs --mangle --output $min
echo "Minified size: $(cat $min | wc -c) bytes ($min)"
echo "Gzipped size: $(cat $min | gzip -c | wc -c) bytes"
else
elm make --output=$js $elm || { exit 1; }
cp $js $min
fi