Files
medtrace-web/Makefile
2025-10-03 09:12:24 -04:00

42 lines
1016 B
Makefile

BUILD_DIR := ./dist
SRC_DIR := ./src
SRCS := $(shell find $(SRC_DIR) -name '*.ts')
OBJS := $(SRCS:$(SRC_DIR)/%.ts=$(BUILD_DIR)/%.js) $(BUILD_DIR)/index.html
HTML_SRCS := $(shell find $(SRC_DIR) -name '*.html')
all: $(OBJS)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Compile the ts files individually
$(BUILD_DIR)/%.js: $(SRC_DIR)/%.ts ./node_modules
mkdir -p $(dir $@)
npx swc $< -o $@
# bundle all the templates into $(BUILD_DIR)/index.html and minify
$(BUILD_DIR)/index.html: export TEMPLATES = $(shell cat $(HTML_SRCS))
$(BUILD_DIR)/index.html: $(HTML_SRCS) $(BUILD_DIR) ./index.template.html
cat ./index.template.html | envsubst '$$TEMPLATES' | tr -d '\n' | sed -r 's/\s+/ /g' > $@
package-lock.json:
npm install --loglevel=http
./node_modules: package-lock.json
npm ci --loglevel=http
serve: all
npx serve -s $(BUILD_DIR)
dev:
npx nodemon --watch $(SRC_DIR) --ext ts,html --exec "make clean && make serve"
clean:
rm -rf $(BUILD_DIR)
nuke:
rm -rf ./node_modules
.PHONY: all clean nuke serve dev