From e0e8700baafdbe9f991f2b0ece65e5837b41d126 Mon Sep 17 00:00:00 2001 From: aleidk Date: Wed, 19 Feb 2025 13:25:35 -0300 Subject: [PATCH] refactor: build fronend via cli to allow watch mode --- .devfiles/init-bun.ts | 3 +++ .justfile | 35 ++++++++++++++--------------------- bunfig.toml | 2 ++ frontend/css/style.css | 2 +- 4 files changed, 20 insertions(+), 22 deletions(-) create mode 100644 .devfiles/init-bun.ts diff --git a/.devfiles/init-bun.ts b/.devfiles/init-bun.ts new file mode 100644 index 0000000..851977d --- /dev/null +++ b/.devfiles/init-bun.ts @@ -0,0 +1,3 @@ +import sassPlugin from "@alecodes/bun-plugin-sass"; + +Bun.plugin(sassPlugin); diff --git a/.justfile b/.justfile index 676fd92..5da0849 100644 --- a/.justfile +++ b/.justfile @@ -3,6 +3,10 @@ mod repo ".devfiles/justfile" set dotenv-load := true +set shell := ["zsh", "-uc"] + +build_mode := env("BUILD_MODE", "DEVELOPMENT") + [private] docker-compose +ARGS: docker compose --file .devfiles/docker/docker-compose.dev.yaml --env-file .env --project-name compendium {{ARGS}} @@ -17,24 +21,13 @@ migrate: (docker-compose "run dbmate migrate") rollback: (docker-compose "run dbmate rollback") build-frontend: - #!/usr/bin/env bun - import sassPlugin from "@alecodes/bun-plugin-sass"; - - const entrypoints = Array.from( - new Bun.Glob("frontend/**/*.html").scanSync(".") - ); - - const result = await Bun.build({ - entrypoints, - outdir: "dist", - publicPath: "/", - splitting: true, - plugins: [sassPlugin], - naming: { - entry: "[dir]/[name].[ext]", - chunk: "assets/[name]-[hash].[ext]", - asset: "assets/[name]-[hash].[ext]", - }, - }); - - console.log("Assets compiled!"); + bun build \ + {{ if uppercase(build_mode) == "DEVELOPMENT" { "--watch" } else { "" } }} \ + --outdir 'dist' \ + --public-path '/' \ + --entry-naming '[dir]/[name].[ext]' \ + --chunk-naming 'assets/[name]-[hash].[ext]' \ + --asset-naming 'assets/[name]-[hash].[ext]' \ + --splitting \ + --css-chunking \ + {{ './frontend/**/*.html' }} diff --git a/bunfig.toml b/bunfig.toml index f694d83..72ab31b 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,3 +1,5 @@ +preload = ["./.devfiles/init-bun.ts"] + [serve.static] plugins = ["bun-plugin-sass"] diff --git a/frontend/css/style.css b/frontend/css/style.css index 818d406..9fab7db 100644 --- a/frontend/css/style.css +++ b/frontend/css/style.css @@ -1,3 +1,3 @@ h1 { - color: red; + color: blue; }