Merge some standalone Vite entries into index.js (#37085)
Keep `swagger` and `external-render-helper` as a standalone entries for external render. - Move `devtest.ts` to `modules/` as init functions - Make external renders correctly load its helper JS and Gitea's current theme - Make external render iframe inherit Gitea's iframe's background color to avoid flicker - Add e2e tests for external render and OpenAPI iframe --------- Co-authored-by: Claude (Opus 4.6) <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
+20
-14
@@ -125,27 +125,33 @@ func getManifestData() *manifestDataStruct {
|
||||
return data
|
||||
}
|
||||
|
||||
// getHashedPath resolves an unhashed asset path (origin path) to its content-hashed path from the frontend manifest.
|
||||
// Example: getHashedPath("js/index.js") returns "js/index.C6Z2MRVQ.js"
|
||||
// Falls back to returning the input path unchanged if the manifest is unavailable.
|
||||
func getHashedPath(originPath string) string {
|
||||
data := getManifestData()
|
||||
if p, ok := data.paths[originPath]; ok {
|
||||
return p
|
||||
}
|
||||
return originPath
|
||||
}
|
||||
|
||||
// AssetURI returns the URI for a frontend asset.
|
||||
// It may return a relative path or a full URL depending on the StaticURLPrefix setting.
|
||||
// In Vite dev mode, known entry points are mapped to their source paths
|
||||
// so the reverse proxy serves them from the Vite dev server.
|
||||
// In production, it resolves the content-hashed path from the manifest.
|
||||
func AssetURI(originPath string) string {
|
||||
if src := viteDevSourceURL(originPath); src != "" {
|
||||
return src
|
||||
if IsViteDevMode() {
|
||||
if src := viteDevSourceURL(originPath); src != "" {
|
||||
return src
|
||||
}
|
||||
// it should be caused by incorrect vite config
|
||||
setting.PanicInDevOrTesting("Failed to locate local path for managed asset URI: %s", originPath)
|
||||
}
|
||||
return setting.StaticURLPrefix + "/assets/" + getHashedPath(originPath)
|
||||
|
||||
// Try to resolve an unhashed asset path (origin path) to its content-hashed path from the frontend manifest.
|
||||
// Example: "js/index.js" -> "js/index.C6Z2MRVQ.js"
|
||||
data := getManifestData()
|
||||
assetPath := data.paths[originPath]
|
||||
if assetPath == "" {
|
||||
// it should be caused by either: "incorrect vite config" or "user's custom theme"
|
||||
assetPath = originPath
|
||||
if !setting.IsProd {
|
||||
log.Warn("Failed to find managed asset URI for origin path: %s", originPath)
|
||||
}
|
||||
}
|
||||
|
||||
return setting.StaticURLPrefix + "/assets/" + assetPath
|
||||
}
|
||||
|
||||
// AssetNameFromHashedPath returns the asset entry name for a given hashed asset path.
|
||||
|
||||
Reference in New Issue
Block a user