From 7a59aab77dba1469a18a94310cc901780573856e Mon Sep 17 00:00:00 2001 From: Yehowshua Immanuel Date: Fri, 3 Jan 2025 08:07:44 -0500 Subject: [PATCH] hopefully building properly now --- .gitignore | 1 + Makefile | 41 ++++++++++++++++++++++++++++------------- frontend/Makefile | 18 +++++++++++++----- frontend/build.sh | 5 +++-- 4 files changed, 45 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index a550ae4..dc3b057 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ frontend/package-lock.json frontend/package.json backend/target public/* +elm-stuff/* diff --git a/Makefile b/Makefile index 5e2fcaf..a5a283a 100644 --- a/Makefile +++ b/Makefile @@ -9,19 +9,33 @@ ELM_MAKE := elm make CARGO_BUILD := cargo build CARGO_RUN := cargo run +ifeq ($(DEBUG)$(RELEASE),) # Both are empty +$(error You must set exactly one of DEBUG=1 or RELEASE=1) +endif + +ifeq ($(DEBUG)$(RELEASE),11) # Both are set +$(error Both DEBUG and RELEASE cannot be set at the same time) +endif + # Targets .PHONY: all frontend backend clean serve -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 +$(PUBLIC_DIR): + mkdir -p $(PUBLIC_DIR) -frontend_debug: - make -C $(FRONTEND_DIR) debug_build - cp $(FRONTEND_DIR)/index.html $(PUBLIC_DIR)/ +$(PUBLIC_DIR)/index.html: $(FRONTEND_DIR)/index.html $(PUBLIC_DIR) + cp $< $@ + +$(FRONTEND_DIR)/elm.min.js: +ifeq ($(DEBUG),1) + make -C $(FRONTEND_DIR) DEBUG=1 +else ifeq ($(RELEASE),1) + make -C $(FRONTEND_DIR) RELEASE=1 +endif + +.PHONY: frontend backend + +frontend: $(PUBLIC_DIR)/index.html $(FRONTEND_DIR)/elm.min.js $(PUBLIC_DIR) cp $(FRONTEND_DIR)/elm.min.js $(PUBLIC_DIR)/ cp $(FRONTEND_DIR)/src/ports.websocket.js $(PUBLIC_DIR)/ mkdir -p $(PUBLIC_DIR)/assets @@ -29,11 +43,12 @@ frontend_debug: backend: $(CARGO_BUILD) --manifest-path=$(BACKEND_DIR)/Cargo.toml -serve: frontend_release backend - $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml - -serve_debug: frontend_debug backend +serve: frontend backend +ifeq ($(DEBUG),1) RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml +else ifeq ($(RELEASE),1) + $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml +endif clean: rm -rf $(PUBLIC_DIR)/* diff --git a/frontend/Makefile b/frontend/Makefile index f3076cd..a7c0b10 100644 --- a/frontend/Makefile +++ b/frontend/Makefile @@ -2,10 +2,18 @@ SRC_FILES := $(shell find src -name "*.elm") all: elm.min.js -debug_build: $(SRC_FILES) - rm -f elm.min.js elm.js - ./build.sh --debug src/Main.elm +ifeq ($(DEBUG)$(RELEASE),) # Both are empty +$(error You must set exactly one of DEBUG=1 or RELEASE=1) +endif -release_build: $(SRC_FILES) - rm -f elm.min.js elm.js +ifeq ($(DEBUG)$(RELEASE),11) # Both are set +$(error Both DEBUG and RELEASE cannot be set at the same time) +endif + + +elm.min.js: $(SRC_FILES) +ifeq ($(DEBUG),1) + ./build.sh --debug src/Main.elm +else ifeq ($(RELEASE),1) ./build.sh --optimize src/Main.elm +endif \ No newline at end of file diff --git a/frontend/build.sh b/frontend/build.sh index 8dac734..e64570f 100755 --- a/frontend/build.sh +++ b/frontend/build.sh @@ -1,6 +1,6 @@ #!/bin/sh -set -e +set -ex js="elm.js" min="elm.min.js" @@ -14,7 +14,8 @@ else 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 +uglifyjs elm.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters=true,keep_fargs=false,unsafe_comps=true,unsafe=true,passes=2' --output=elm.js +uglifyjs elm.js --mangle --output=elm.js echo "Compiled size: $(wc -c < $js) bytes ($js)" echo "Minified size: $(wc -c < $min) bytes ($min)"