build: generate fingerprinted assets before compile

This commit is contained in:
Sora39831 2026-04-07 16:43:18 +08:00
parent cfb169d2fb
commit 5ad2203f24
3 changed files with 20 additions and 0 deletions

View file

@ -15,6 +15,7 @@ COPY . .
ENV CGO_ENABLED=1 ENV CGO_ENABLED=1
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE" ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
RUN go run ./cmd/genassets
RUN go build -ldflags "-w -s" -o build/x-ui main.go RUN go build -ldflags "-w -s" -o build/x-ui main.go
RUN ./DockerInit.sh "$TARGETARCH" RUN ./DockerInit.sh "$TARGETARCH"

View file

@ -30,6 +30,17 @@ bash <(curl -Ls https://raw.githubusercontent.com/Sora39831/3x-ui/master/install
For full documentation, please visit the [project Wiki](https://github.com/Sora39831/3x-ui/wiki). For full documentation, please visit the [project Wiki](https://github.com/Sora39831/3x-ui/wiki).
## Building from source
Generate fingerprinted frontend assets before compiling:
```bash
go run ./cmd/genassets
go build -ldflags "-w -s" -o build/x-ui main.go
```
Production builds embed files from `web/public/assets` and `web/public/assets-manifest.json`.
## A Special Thanks to ## A Special Thanks to
- [alireza0](https://github.com/alireza0/) - [alireza0](https://github.com/alireza0/)

View file

@ -85,3 +85,11 @@ func TestAssetRequestCacheControlDoesNotMarkMissingFingerprintPathImmutable(t *t
t.Fatalf("expected missing asset path to avoid immutable cache-control, got %q", got) t.Fatalf("expected missing asset path to avoid immutable cache-control, got %q", got)
} }
} }
func TestAssetCacheControlForLogicalPathIsShortLived(t *testing.T) {
got := assetCacheControl("js/websocket.js")
want := "public, max-age=300"
if got != want {
t.Fatalf("expected %q, got %q", want, got)
}
}