Skip to content

Commit 1a8973d

Browse files
j-maasY0hy0h
authored and
Y0hy0h
committed
Replace uglifyjs with terser
terser does not require two passes and does everything with one call.
1 parent 3867036 commit 1a8973d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

hints/optimize.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ Okay, but how do we get those numbers?
1515

1616
Step one is to compile with the `--optimize` flag. This does things like shortening record field names and unboxing values.
1717

18-
Step two is to call `uglifyjs` with a bunch of special flags. The flags unlock optimizations that are unreliable in normal JS code, but because Elm does not have side-effects, they work fine for us!
18+
Step two is to call `terser` with a bunch of special flags. The flags unlock optimizations that are unreliable in normal JS code, but because Elm does not have side-effects, they work fine for us!
1919

2020
Putting those together, here is how I would optimize `src/Main.elm` with two terminal commands:
2121

2222
```bash
2323
elm make src/Main.elm --optimize --output=elm.js
24-
uglifyjs elm.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=elm.min.js
24+
terser elm.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" --mangle --output=elm.min.js
2525
```
2626

2727
After this you will have an `elm.js` and a significantly smaller `elm.min.js` file!
2828

29-
**Note 1:** `uglifyjs` is called twice there. First to `--compress` and second to `--mangle`. This is necessary! Otherwise `uglifyjs` will ignore our `pure_funcs` flag.
30-
31-
**Note 2:** If the `uglifyjs` command is not available in your terminal, you can run the command `npm install uglify-js --global` to download it. You probably already have `npm` from getting `elm repl` working, but if not, it is bundled with [nodejs](https://nodejs.org/).
29+
**Note:** If the `terser` command is not available in your terminal, you can run the command `npm install terser --global` to download it. You probably already have `npm` from getting `elm repl` working, but if not, it is bundled with [nodejs](https://nodejs.org/).
3230

3331
## Scripts
3432

@@ -46,7 +44,7 @@ min="elm.min.js"
4644

4745
elm make --optimize --output=$js $@
4846

49-
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
47+
terser $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" --mangle --output=$min
5048

5149
echo "Initial size: $(cat $js | wc -c) bytes ($js)"
5250
echo "Minified size:$(cat $min | wc -c) bytes ($min)"
@@ -55,5 +53,5 @@ echo "Gzipped size: $(cat $min | gzip -c | wc -c) bytes"
5553

5654
It also prints out all the asset sizes for you! Your server should be configured to gzip the assets it sends, so the last line is telling you how many bytes would _actually_ get sent to the user.
5755

58-
Again, the important commands are `elm` and `uglifyjs` which work on any platform, so it should not be too tough to do something similar on Windows.
56+
Again, the important commands are `elm` and `terser` which work on any platform, so it should not be too tough to do something similar on Windows.
5957

0 commit comments

Comments
 (0)