diff --git a/.gitignore b/.gitignore index b51ea71..b947077 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ node_modules/ -build/ \ No newline at end of file +dist/ diff --git a/.swcrc b/.swcrc new file mode 100644 index 0000000..d1d8d8f --- /dev/null +++ b/.swcrc @@ -0,0 +1,9 @@ +{ + "jsc": { + "parser": { + "syntax": "typescript" + }, + "target": "esnext" + }, + "isModule": true +} \ No newline at end of file diff --git a/Makefile b/Makefile index f88d4d2..5e6ad60 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,31 @@ -build/MyCard.js: ./node_modules ./build - npx swc ./src/MyCard.ts -o ./build/MyCard.js +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') -./build: - mkdir -p ./build +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 +$(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' > $@ ./node_modules: npm install -serve: ./build/MyCard.js - npx serve +serve: all + npx serve -s $(BUILD_DIR) clean: - rm -rf ./build ./node_modules + rm -rf $(BUILD_DIR) ./node_modules -.PHONY: clean serve \ No newline at end of file +.PHONY: all clean serve \ No newline at end of file diff --git a/index.html b/index.html deleted file mode 100644 index e272e50..0000000 --- a/index.html +++ /dev/null @@ -1,90 +0,0 @@ - - -
-