45 lines
1.8 KiB
Bash
Executable File
45 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# After flutter build web: bust CDN/browser cache for bootstrap + main.dart.js.
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
WEB="$ROOT/build/web"
|
|
INDEX="$WEB/index.html"
|
|
BOOT="$WEB/flutter_bootstrap.js"
|
|
|
|
if [ ! -f "$INDEX" ]; then
|
|
echo "Missing $INDEX — run flutter build web first." >&2
|
|
exit 1
|
|
fi
|
|
|
|
STAMP="$(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo nogit)-$(date +%Y%m%d%H%M%S)"
|
|
echo "Web cache-bust stamp: $STAMP"
|
|
|
|
# index.html: versioned bootstrap URL (index.html is no-cache at origin).
|
|
if grep -q 'flutter_bootstrap.js' "$INDEX"; then
|
|
sed -i "s|flutter_bootstrap.js[^\"']*|flutter_bootstrap.js?v=${STAMP}|g" "$INDEX"
|
|
fi
|
|
|
|
# flutter_bootstrap.js: versioned main.dart.js load path in buildConfig.
|
|
if [ -f "$BOOT" ]; then
|
|
sed -i "s|\"mainJsPath\":\"main.dart.js\"|\"mainJsPath\":\"main.dart.js?v=${STAMP}\"|g" "$BOOT"
|
|
fi
|
|
|
|
# Icon font: in production the .otf is cached for a day, and historically the
|
|
# tree-shaken MaterialIcons subset changed between builds under the SAME filename
|
|
# — so stale caches made newly-used glyphs (settings, admin_panel_settings)
|
|
# render blank. Rename the font per build and rewrite FontManifest.json so a new
|
|
# URL is always fetched. Pairs with --no-tree-shake-icons (full, stable font).
|
|
FONT_DIR="$WEB/assets/fonts"
|
|
FONT_MANIFEST="$WEB/assets/FontManifest.json"
|
|
SRC_FONT="$FONT_DIR/MaterialIcons-Regular.otf"
|
|
if [ -f "$SRC_FONT" ] && [ -f "$FONT_MANIFEST" ]; then
|
|
NEW_FONT="MaterialIcons-Regular.${STAMP}.otf"
|
|
cp -f "$SRC_FONT" "$FONT_DIR/$NEW_FONT"
|
|
sed -i "s|fonts/MaterialIcons-Regular[^\"]*\.otf|fonts/${NEW_FONT}|g" "$FONT_MANIFEST"
|
|
echo "Stamped MaterialIcons font URL: fonts/$NEW_FONT"
|
|
fi
|
|
|
|
printf '%s\n' "$STAMP" >"$WEB/BUILD_STAMP.txt"
|
|
echo "Stamped: $INDEX and flutter_bootstrap.js (if present)"
|