now supporting debug and release builds

This commit is contained in:
Yehowshua Immanuel 2024-12-31 21:14:09 -05:00
parent 0412bc04c8
commit 66b243a107
5 changed files with 42 additions and 26 deletions

View file

@ -12,10 +12,15 @@ CARGO_RUN := cargo run
# Targets
.PHONY: all frontend backend clean serve
all: frontend backend
frontend_release:
make -C $(FRONTEND_DIR) release_build
cp $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)/
cp $(FRONTEND_DIR)/elm.min.js $(PUBLIC_DIR)/
cp $(FRONTEND_DIR)/src/ports.websocket.js $(PUBLIC_DIR)/
mkdir -p $(PUBLIC_DIR)/assets
frontend:
make -C $(FRONTEND_DIR) elm.min.js
frontend_debug:
make -C $(FRONTEND_DIR) debug_build
cp $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)/
cp $(FRONTEND_DIR)/elm.min.js $(PUBLIC_DIR)/
cp $(FRONTEND_DIR)/src/ports.websocket.js $(PUBLIC_DIR)/
@ -24,10 +29,10 @@ frontend:
backend:
$(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml
serve: all
serve: frontend_release backend
$(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml
serve_debug: all
serve_debug: frontend_debug backend
RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml
clean:

View file

@ -3,22 +3,23 @@ Example demonstrating how one might architect a single page application
Elm app.
# Dependencies MacOS
You will need to have rust and cargo installed on MacOS.
```bash
brew install node elm
npm install -g uglify-js@2.4.11
```
# Building
```
make serve
```
`make serve` or `make serve_debug`
Now open `http://localhost:8000` in your browser.
Now open `http://127.0.0.1:8080` in your browser.
# TODO
- [x] Add Makefile
- [ ] Add GPLV3 License
- [ ] Add `make release` target that is nix ready...
- [ ] Determine if `src/Body.elm` or pages in `src/Page` should have subscription functions
- [ ] use actix backend that maps most root requests to serve `actix_file::Files`
- [ ] Submit to slack for feedback...

View file

@ -2,6 +2,10 @@ SRC_FILES := $(shell find src -name "*.elm")
all: elm.min.js
elm.min.js: $(SRC_FILES)
debug_build: $(SRC_FILES)
rm -f elm.min.js elm.js
./optimize.sh src/Main.elm
./build.sh --debug src/Main.elm
release_build: $(SRC_FILES)
rm -f elm.min.js elm.js
./build.sh --optimize src/Main.elm

21
frontend/build.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
set -e
js="elm.js"
min="elm.min.js"
if [ "$1" = "--debug" ]; then
elm make --debug --output=$js "${@:2}"
elif [ "$1" = "--optimize" ]; then
elm make --optimize --output=$js "${@:2}"
else
echo "Error: You must specify either --debug or --optimize."
exit 1
fi
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 "Compiled size: $(wc -c < $js) bytes ($js)"
echo "Minified size: $(wc -c < $min) bytes ($min)"
echo "Gzipped size: $(gzip -c $min | wc -c) bytes"

View file

@ -1,15 +0,0 @@
#!/bin/sh
set -e
js="elm.js"
min="elm.min.js"
elm make --debug --output=$js "$@"
# elm make --optimize --debug --output=$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 "Compiled size:$(wc $js -c) bytes ($js)"
echo "Minified size:$(wc $min -c) bytes ($min)"
echo "Gzipped size: $(gzip $min -c | wc -c) bytes"