perf(frontend): add build.rs asset pipeline with oxc + lightningcss
- Bundle 31 JS files → single app.{hash}.js (oxc minifier)
- Bundle 36 CSS files → single app.{hash}.css (lightningcss)
- Resolve CSS @import chains at build time
- Inline theme-init.js to eliminate render-blocking script
- Minify all individual JS/CSS/JSON assets in static-dist/
- Auto-update Service Worker cache manifest with bundle hashes
- FNV hash-based cache-busting filenames
Results: 88 → 12 requests, 640 kB → 96.5 kB transferred (-85%)
Build modes:
- Debug: copies HTML to OUT_DIR, serves original static/
- Release: generates static-dist/ with processed assets
Also:
- Update Dockerfile to include build.rs in cacher stage
- Serve static-dist/ in release Docker builds
- Remove host static/ bind mount from docker-compose
- Switch include_str!() to OUT_DIR for all HTML pages
This commit is contained in:
+8
-5
@@ -4,11 +4,14 @@ WORKDIR /app
|
||||
RUN apk --no-cache upgrade && \
|
||||
apk add --no-cache musl-dev pkgconfig postgresql-dev gcc perl make
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
# build.rs + static/ are needed so the build script can run and set OUT_DIR
|
||||
COPY build.rs ./
|
||||
COPY static static
|
||||
# Create a minimal project to download and cache dependencies
|
||||
RUN mkdir -p src && \
|
||||
echo 'fn main() { println!("Dummy build for caching dependencies"); }' > src/main.rs && \
|
||||
RUSTFLAGS="-C target-cpu=native" cargo build --release && \
|
||||
rm -rf src target/release/deps/oxicloud*
|
||||
rm -rf src static-dist target/release/deps/oxicloud* target/release/build/oxicloud-*
|
||||
# Stage 2: Build the application
|
||||
FROM rust:1.94.0-alpine3.23 AS builder
|
||||
WORKDIR /app
|
||||
@@ -17,8 +20,8 @@ RUN apk --no-cache upgrade && \
|
||||
# Copy cached dependencies (only target dir and cargo registry)
|
||||
COPY --from=cacher /app/target target
|
||||
COPY --from=cacher /usr/local/cargo/registry /usr/local/cargo/registry
|
||||
# Copy source and static (login.html is embedded at compile-time via include_str!)
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
# Copy source, build script, and static assets
|
||||
COPY Cargo.toml Cargo.lock build.rs ./
|
||||
COPY src src
|
||||
COPY static static
|
||||
COPY db db
|
||||
@@ -54,8 +57,8 @@ RUN chmod +x /usr/local/bin/oxicloud
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Copy static files and other resources needed at runtime
|
||||
COPY --chown=oxicloud:oxicloud static /app/static
|
||||
# Copy processed static files (bundled/minified by build.rs in release)
|
||||
COPY --from=builder --chown=oxicloud:oxicloud /app/static-dist /app/static
|
||||
COPY --chown=oxicloud:oxicloud db /app/db
|
||||
|
||||
# Create storage directory with proper permissions
|
||||
|
||||
Reference in New Issue
Block a user