mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-09 15:38:03 -05:00
feat: implement CDN URL support for asset loading and add replacement script
This commit is contained in:
@@ -10,7 +10,13 @@ fi
|
||||
|
||||
echo "Replacing pre-baked value.."
|
||||
|
||||
# Replace in JS files in assets directory
|
||||
find assets -type f -name "*.js" |
|
||||
while read file; do
|
||||
sed -i "s|$ORIGINAL|$REPLACEMENT|g" "$file"
|
||||
done
|
||||
|
||||
# Replace in index.html (for asset references)
|
||||
if [ -f "index.html" ]; then
|
||||
sed -i "s|$ORIGINAL|$REPLACEMENT|g" "index.html"
|
||||
fi
|
||||
|
||||
@@ -29,14 +29,14 @@ export default defineConfig(({ mode }) => {
|
||||
"0.0.1"
|
||||
).replaceAll(".", "-");
|
||||
|
||||
// Optional CDN URL for static assets (e.g., https://cdn.example.com)
|
||||
// When set, all static assets will be served from this URL instead of the same origin.
|
||||
// This is useful for serving assets from a CDN subdomain while keeping API calls on the main domain.
|
||||
// If not set, assets are served from the same origin (backward compatible).
|
||||
// CDN URL for static assets in /assets/* only.
|
||||
// Docker: Set CDN_URL env var at runtime (placeholder replaced at container startup).
|
||||
// Direct build: Use --build-arg CDN_URL=https://... or VITE_CDN_URL env var.
|
||||
// Default: Empty = same-origin asset loading.
|
||||
const cdnUrl = env.VITE_CDN_URL || "";
|
||||
|
||||
return {
|
||||
base: cdnUrl || "/",
|
||||
base: "/",
|
||||
server: {
|
||||
allowedHosts,
|
||||
host: true,
|
||||
@@ -59,6 +59,15 @@ export default defineConfig(({ mode }) => {
|
||||
}
|
||||
}
|
||||
},
|
||||
experimental: {
|
||||
// Only apply CDN URL to files in /assets/* directory
|
||||
renderBuiltUrl(filename) {
|
||||
if (filename.startsWith("assets/")) {
|
||||
return `${cdnUrl}/${filename}`;
|
||||
}
|
||||
return `/${filename}`;
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
tsconfigPaths(),
|
||||
nodePolyfills({
|
||||
|
||||
Reference in New Issue
Block a user