refactor: build fronend via cli to allow watch mode

This commit is contained in:
Alexander Navarro 2025-02-19 13:25:35 -03:00
parent 3e0dd79217
commit e0e8700baa
4 changed files with 20 additions and 22 deletions

3
.devfiles/init-bun.ts Normal file
View file

@ -0,0 +1,3 @@
import sassPlugin from "@alecodes/bun-plugin-sass";
Bun.plugin(sassPlugin);

View file

@ -3,6 +3,10 @@ mod repo ".devfiles/justfile"
set dotenv-load := true set dotenv-load := true
set shell := ["zsh", "-uc"]
build_mode := env("BUILD_MODE", "DEVELOPMENT")
[private] [private]
docker-compose +ARGS: docker-compose +ARGS:
docker compose --file .devfiles/docker/docker-compose.dev.yaml --env-file .env --project-name compendium {{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") rollback: (docker-compose "run dbmate rollback")
build-frontend: build-frontend:
#!/usr/bin/env bun bun build \
import sassPlugin from "@alecodes/bun-plugin-sass"; {{ if uppercase(build_mode) == "DEVELOPMENT" { "--watch" } else { "" } }} \
--outdir 'dist' \
const entrypoints = Array.from( --public-path '/' \
new Bun.Glob("frontend/**/*.html").scanSync(".") --entry-naming '[dir]/[name].[ext]' \
); --chunk-naming 'assets/[name]-[hash].[ext]' \
--asset-naming 'assets/[name]-[hash].[ext]' \
const result = await Bun.build({ --splitting \
entrypoints, --css-chunking \
outdir: "dist", {{ './frontend/**/*.html' }}
publicPath: "/",
splitting: true,
plugins: [sassPlugin],
naming: {
entry: "[dir]/[name].[ext]",
chunk: "assets/[name]-[hash].[ext]",
asset: "assets/[name]-[hash].[ext]",
},
});
console.log("Assets compiled!");

View file

@ -1,3 +1,5 @@
preload = ["./.devfiles/init-bun.ts"]
[serve.static] [serve.static]
plugins = ["bun-plugin-sass"] plugins = ["bun-plugin-sass"]

View file

@ -1,3 +1,3 @@
h1 { h1 {
color: red; color: blue;
} }