chore(external): dist path

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei
2024-10-25 23:25:20 +08:00
parent f87c0ff2ab
commit fa573c4384
4 changed files with 36 additions and 14 deletions
-12
View File
@@ -41,19 +41,7 @@ const prodHandler = (app: FastifyInstance) => {
const upstreamEnv = req.requestContext.get("upstreamEnv")
if (isInVercelReverseProxy || upstreamEnv === "prod") {
// Add asset prefix
// Map all link and script to /assets
// <script type="module" crossorigin src="/assets/index-kQ31_hj7.js"></script>
// <link rel="stylesheet" crossorigin href="/assets/index-BORNdGZP.css">
const prefix = "/external-dist"
const { document } = parseHTML(template)
for (const script of document.querySelectorAll("script")) {
script.src = `${prefix}${script.src}`
}
for (const link of document.querySelectorAll("link")) {
link.href = `${prefix}${link.href}`
}
const upstreamEnv = req.requestContext.get("upstreamEnv")
if (upstreamEnv) {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"rewrites": [
{
"source": "/((?!external-dist).*)",
"source": "/((?!external-dist|dist-external).*)",
"destination": "/api"
}
]
+9
View File
@@ -18,6 +18,15 @@ export default () => {
...viteRenderBaseConfig.define,
ELECTRON: "false",
},
build: {
rollupOptions: {
output: {
assetFileNames: "dist-external/[name]-[hash].[ext]",
chunkFileNames: "dist-external/[name]-[hash].js",
entryFileNames: "dist-external/[name]-[hash].js",
},
},
},
plugins: [react(), twMacro()],
server: {
+26 -1
View File
@@ -21,7 +21,11 @@
"destination": "https://follow-external-ssr.vercel.app/:path*"
},
{
"source": "/((?!assets|vendor|locales/).*)",
"source": "/dist-external/:path*",
"destination": "https://follow-external-ssr.vercel.app/dist-external/:path*"
},
{
"source": "/((?!assets|vendor|locales|dist-external/).*)",
"destination": "/index.html"
}
],
@@ -79,6 +83,27 @@
"value": "max-age=604800"
}
]
},
{
"source": "/dist-external/(.*)",
"headers": [
{
"key": "Cache-Control",
"value": "public, max-age=604800, immutable"
},
{
"key": "CDN-Cache-Control",
"value": "max-age=604800"
},
{
"key": "Vercel-CDN-Cache-Control",
"value": "max-age=604800"
},
{
"key": "Cloudflare-CDN-Cache-Control",
"value": "max-age=604800"
}
]
}
]
}