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

View file

@ -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' }}