build: move generated assets to dist
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,8 +5,7 @@ node_modules
|
|||||||
out
|
out
|
||||||
dist
|
dist
|
||||||
*.tgz
|
*.tgz
|
||||||
static/tailwind.css
|
dist/
|
||||||
static/*.js
|
|
||||||
|
|
||||||
# code coverage
|
# code coverage
|
||||||
coverage
|
coverage
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ go test ./...
|
|||||||
go run ./cmd/server
|
go run ./cmd/server
|
||||||
```
|
```
|
||||||
|
|
||||||
TypeScript source files live in `static/*.ts` and are bundled to matching `static/*.js` files for runtime.
|
TypeScript source files live in `static/*.ts` and are bundled to runtime assets in `dist/`.
|
||||||
Generated `static/*.js` and `static/tailwind.css` files are ignored by git.
|
Generated `dist/` files are ignored by git.
|
||||||
|
|
||||||
## Development guidelines
|
## Development guidelines
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ RUN mkdir -p /app/data
|
|||||||
|
|
||||||
COPY --from=builder /app/main_server .
|
COPY --from=builder /app/main_server .
|
||||||
COPY --from=builder /app/static ./static
|
COPY --from=builder /app/static ./static
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
COPY --from=builder /app/migrations ./migrations
|
COPY --from=builder /app/migrations ./migrations
|
||||||
|
|
||||||
# Expose the application port
|
# Expose the application port
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ bun run build:assets
|
|||||||
go run ./cmd/server
|
go run ./cmd/server
|
||||||
```
|
```
|
||||||
|
|
||||||
The frontend pipeline uses a single source stylesheet (`static/style.css`) and TypeScript sources in `static/*.ts`, then emits build artifacts (`static/tailwind.css` and `static/*.js`) for serving.
|
The frontend pipeline uses a single source stylesheet (`static/style.css`) and TypeScript sources in `static/*.ts`, then emits build artifacts into `dist/` (`dist/tailwind.css` and `dist/*.js`) for serving.
|
||||||
|
|
||||||
When the server starts, the app is available at `http://localhost:3000`.
|
When the server starts, the app is available at `http://localhost:3000`.
|
||||||
|
|
||||||
|
|||||||
@@ -32,6 +32,10 @@ func NewRouter(cfg Config) http.Handler {
|
|||||||
fs := http.FileServer(http.Dir("./static"))
|
fs := http.FileServer(http.Dir("./static"))
|
||||||
mux.Handle("/static/", http.StripPrefix("/static/", fs))
|
mux.Handle("/static/", http.StripPrefix("/static/", fs))
|
||||||
|
|
||||||
|
// Serve built frontend assets
|
||||||
|
dist := http.FileServer(http.Dir("./dist"))
|
||||||
|
mux.Handle("/dist/", http.StripPrefix("/dist/", dist))
|
||||||
|
|
||||||
mux.HandleFunc("/", animeHandler.HandleCatalog)
|
mux.HandleFunc("/", animeHandler.HandleCatalog)
|
||||||
mux.HandleFunc("/discover", animeHandler.HandleDiscover)
|
mux.HandleFunc("/discover", animeHandler.HandleDiscover)
|
||||||
mux.HandleFunc("/notifications", animeHandler.HandleNotifications)
|
mux.HandleFunc("/notifications", animeHandler.HandleNotifications)
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ templ Layout(title string, showHeader bool) {
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
<title>{ title }</title>
|
<title>{ title }</title>
|
||||||
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg"/>
|
<link rel="icon" type="image/svg+xml" href="/static/favicon.svg"/>
|
||||||
<link rel="stylesheet" href="/static/tailwind.css"/>
|
<link rel="stylesheet" href="/dist/tailwind.css"/>
|
||||||
<script src="https://unpkg.com/htmx.org@1.9.11"></script>
|
<script src="https://unpkg.com/htmx.org@1.9.11"></script>
|
||||||
<script src="/static/discover.js" defer></script>
|
<script src="/dist/discover.js" defer></script>
|
||||||
<script src="/static/anime.js" defer></script>
|
<script src="/dist/anime.js" defer></script>
|
||||||
<script src="/static/timezone.js" defer></script>
|
<script src="/dist/timezone.js" defer></script>
|
||||||
<script src="/static/auth.js" defer></script>
|
<script src="/dist/auth.js" defer></script>
|
||||||
</head>
|
</head>
|
||||||
<body class="min-h-screen bg-[var(--bg)] text-[var(--text)] font-[var(--font)] text-[14px] leading-[1.45]">
|
<body class="min-h-screen bg-[var(--bg)] text-[var(--text)] font-[var(--font)] text-[14px] leading-[1.45]">
|
||||||
if showHeader {
|
if showHeader {
|
||||||
@@ -48,7 +48,7 @@ templ Layout(title string, showHeader bool) {
|
|||||||
}>
|
}>
|
||||||
{ children... }
|
{ children... }
|
||||||
</main>
|
</main>
|
||||||
<script src="/static/search.js"></script>
|
<script src="/dist/search.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
"name": "myanimelist-ui",
|
"name": "myanimelist-ui",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build:css": "bunx @tailwindcss/cli -i ./static/style.css -o ./static/tailwind.css",
|
"build:css": "bunx @tailwindcss/cli -i ./static/style.css -o ./dist/tailwind.css",
|
||||||
"watch:css": "bunx @tailwindcss/cli -i ./static/style.css -o ./static/tailwind.css --watch",
|
"watch:css": "bunx @tailwindcss/cli -i ./static/style.css -o ./dist/tailwind.css --watch",
|
||||||
"build:ts": "bun build ./static/*.ts --outdir ./static --target browser",
|
"build:ts": "bun build ./static/*.ts --outdir ./dist --target browser",
|
||||||
"typecheck": "bunx tsc -p tsconfig.json --noEmit",
|
"typecheck": "bunx tsc -p tsconfig.json --noEmit",
|
||||||
"build:assets": "bun run build:css && bun run build:ts"
|
"build:assets": "bun run build:css && bun run build:ts"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user