diff --git a/Makefile b/Makefile index d7a000b..5e2fcaf 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/README.md b/README.md index f6ea50a..3a631b7 100644 --- a/README.md +++ b/README.md @@ -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... diff --git a/frontend/Makefile b/frontend/Makefile index c37a9c6..f3076cd 100644 --- a/frontend/Makefile +++ b/frontend/Makefile @@ -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 diff --git a/frontend/build.sh b/frontend/build.sh new file mode 100755 index 0000000..8dac734 --- /dev/null +++ b/frontend/build.sh @@ -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" diff --git a/frontend/optimize.sh b/frontend/optimize.sh deleted file mode 100755 index 7016792..0000000 --- a/frontend/optimize.sh +++ /dev/null @@ -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"