-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Migrate from webpack to Vite 8 #36896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
silverwind
wants to merge
59
commits into
go-gitea:main
Choose a base branch
from
silverwind:vite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,203
−1,572
Open
Changes from 9 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
d99e932
Migrate from webpack to Vite 8
silverwind 89b16a1
Use content-hashed filenames with Vite manifest for cache busting
silverwind 90374c1
Hash all asset filenames and remove AssetVersion
silverwind a3d579e
Merge branch 'main' into vite
silverwind dea0436
Rename template helper `AssetPath` to `GetAssetPath` and clean up
silverwind 581bd1b
cleanup
silverwind a419e10
Fix webcomponents manifest entry not written
silverwind e701562
inline
silverwind 2a198b0
Remove duplicate `webcomponents-blocking.ts`
silverwind 6533de7
Address review comments on `vite.config.ts`
silverwind e9554c7
Add upstream issue link for ENABLE_SOURCEMAP comment
silverwind df3c17a
add ref
silverwind 6215c5e
Simplify ENABLE_SOURCEMAP handling
silverwind d6b34b3
Restore ENABLE_SOURCEMAP=reduced mode with Vite plugin
silverwind 17ab78e
Restore original ENABLE_SOURCEMAP variable names from webpack config
silverwind c160f2b
Merge branch 'main' into vite
silverwind 5fb3d15
Update modules/public/manifest.go
silverwind c52a9da
Restore ENABLE_SOURCEMAP=reduced mode with Vite plugin
silverwind 3fcea7d
Apply suggestion from @silverwind
silverwind 4a83e14
Build index.js as blocking IIFE, load index-domready as deferred module
silverwind 43df852
Use global jQuery, remove jquery-global plugin, simplify CSS handling
silverwind e13f106
Use AssetFS() for Vite manifest reading
silverwind 745cc7d
Simplify manifest loading, remove htmx from IIFE
silverwind 70568dd
Use Vite's Manifest type for manifest handling
silverwind e0b1ad8
Add jQuery to vitest setup for global $ in tests
silverwind 14744ac
Update stale webpack references to vite
silverwind ef8811f
forbid jquery imports because of single global instance
silverwind fee04f3
Suppress plugin timing warnings for worker builds
silverwind 93ce326
Extract shared rolldownOptions for main, IIFE and worker builds
silverwind ae24785
use function
silverwind b5d5e46
Remove reduced sourcemap mode, simplify to true/false
silverwind bc05ab5
fix comment
wxiaoguang 467dde9
add jQuery check to devtest page
wxiaoguang 6ae005d
Use atomic.Pointer for manifest state to fix data race in dev mode
silverwind f3a8a19
Move htmx to IIFE globals, forbid `htmx.org` imports
silverwind e66d7b4
eslint tweaks
silverwind f0cf85d
C O M M E N T
wxiaoguang be08926
Stub XPathEvaluator in vitest setup for htmx compatibility
silverwind 1487b7a
fix parseManifest
wxiaoguang 1efff94
Stub XPathEvaluator in vitest setup for htmx compatibility
silverwind 412ba3c
Merge tiny mermaid parser chunks via `manualChunks`
silverwind 303328b
fix lint
silverwind 18070c4
Use `codeSplitting` instead of deprecated `manualChunks`
silverwind c098499
Merge mermaid diagram chunks into single `mermaid-core` chunk
silverwind 9ff8789
Remove redundant `minSize: 0` from mermaid-core group
silverwind 4c5b77c
Remove unnecessary priority from vue-runtime group
silverwind c6f6ea8
add UnencryptedHTTP2
wxiaoguang 2040535
Merge mermaid chunks without making them static imports
silverwind 592b67b
fmt
silverwind e768b5c
comment
silverwind 89f8907
Remove shared chunk dependencies from swagger entry
silverwind 1dacad8
Move relative-time to own
silverwind 93e92fa
Clean up vite config
silverwind 80a31ec
Add citation-js codeSplitting group, update comment
silverwind f9201be
Merge branch 'main' into vite
silverwind 2101c2e
explicit minify
silverwind 0648217
Restore process.env.NODE_ENV define for IIFE build, remove citation-j…
silverwind 4746fdd
Merge remote-tracking branch 'origin/main' into vite
silverwind 4797006
Remove stale fomantic.css import
silverwind File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package public | ||
|
|
||
| import ( | ||
| "os" | ||
| "path" | ||
| "path/filepath" | ||
| "sync" | ||
|
|
||
| "code.gitea.io/gitea/modules/json" | ||
| "code.gitea.io/gitea/modules/log" | ||
| "code.gitea.io/gitea/modules/setting" | ||
| ) | ||
|
|
||
| type viteManifestEntry struct { | ||
| File string `json:"file"` | ||
| Name string `json:"name"` | ||
| IsEntry bool `json:"isEntry"` | ||
| CSS []string `json:"css"` | ||
| } | ||
|
|
||
| var ( | ||
| manifestMu sync.RWMutex | ||
| manifestPaths map[string]string | ||
| manifestModTime int64 | ||
| ) | ||
|
|
||
| func manifestDiskPath() string { | ||
| return filepath.Join(setting.StaticRootPath, "public", "assets", ".vite", "manifest.json") | ||
| } | ||
|
|
||
| func parseManifest(data []byte) map[string]string { | ||
| var manifest map[string]viteManifestEntry | ||
| if err := json.Unmarshal(data, &manifest); err != nil { | ||
| log.Error("Failed to parse Vite manifest: %v", err) | ||
| return nil | ||
| } | ||
|
|
||
| paths := make(map[string]string) | ||
| for _, entry := range manifest { | ||
| if !entry.IsEntry || entry.Name == "" { | ||
| continue | ||
| } | ||
| // Build unhashed key from file path: "js/index.js", "css/theme-gitea-dark.css" | ||
| dir := path.Dir(entry.File) | ||
| ext := path.Ext(entry.File) | ||
| key := dir + "/" + entry.Name + ext | ||
| paths[key] = entry.File | ||
| // Map associated CSS files, e.g. "css/index.css" -> "css/index.B3zrQPqD.css" | ||
| for _, css := range entry.CSS { | ||
| cssKey := path.Dir(css) + "/" + entry.Name + path.Ext(css) | ||
| paths[cssKey] = css | ||
| } | ||
| } | ||
| return paths | ||
| } | ||
|
|
||
| func getManifestPaths() map[string]string { | ||
| diskPath := manifestDiskPath() | ||
|
|
||
| manifestMu.RLock() | ||
| if manifestPaths != nil { | ||
| fi, statErr := os.Stat(diskPath) | ||
| if statErr != nil || fi.ModTime().UnixNano() == manifestModTime { | ||
| paths := manifestPaths | ||
| manifestMu.RUnlock() | ||
| return paths | ||
| } | ||
| } | ||
| manifestMu.RUnlock() | ||
|
|
||
| manifestMu.Lock() | ||
| defer manifestMu.Unlock() | ||
|
|
||
| // Double-check after acquiring write lock | ||
| fi, statErr := os.Stat(diskPath) | ||
silverwind marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if manifestPaths != nil { | ||
| if statErr != nil || fi.ModTime().UnixNano() == manifestModTime { | ||
| return manifestPaths | ||
| } | ||
| } | ||
|
|
||
| // Read from disk if available, otherwise from AssetFS (bindata) | ||
| var data []byte | ||
| var err error | ||
| if statErr == nil { | ||
| data, err = os.ReadFile(diskPath) | ||
| } else { | ||
| data, err = AssetFS().ReadFile("assets", ".vite", "manifest.json") | ||
| } | ||
| if err != nil { | ||
| log.Error("Failed to read Vite manifest: %v", err) | ||
| manifestPaths = make(map[string]string) | ||
| return manifestPaths | ||
| } | ||
|
|
||
| paths := parseManifest(data) | ||
| if paths == nil { | ||
| paths = make(map[string]string) | ||
| } | ||
| manifestPaths = paths | ||
| if fi != nil { | ||
| manifestModTime = fi.ModTime().UnixNano() | ||
| } | ||
| return manifestPaths | ||
| } | ||
|
|
||
| // GetAssetPath resolves an unhashed asset path to its content-hashed path from the Vite manifest. | ||
| // Example: GetAssetPath("js/index.js") returns "js/index.C6Z2MRVQ.js" | ||
| // Falls back to returning the input path unchanged if the manifest is unavailable. | ||
| func GetAssetPath(name string) string { | ||
| paths := getManifestPaths() | ||
| if p, ok := paths[name]; ok { | ||
| return p | ||
| } | ||
| return name | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Copyright 2025 The Gitea Authors. All rights reserved. | ||
silverwind marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package public | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestParseManifest(t *testing.T) { | ||
| manifest := []byte(`{ | ||
| "web_src/js/index.ts": { | ||
| "file": "js/index.C6Z2MRVQ.js", | ||
| "name": "index", | ||
| "src": "web_src/js/index.ts", | ||
| "isEntry": true, | ||
| "css": ["css/index.B3zrQPqD.css"] | ||
| }, | ||
| "web_src/js/standalone/swagger.ts": { | ||
| "file": "js/swagger.SujiEmYM.js", | ||
| "name": "swagger", | ||
| "src": "web_src/js/standalone/swagger.ts", | ||
| "isEntry": true, | ||
| "css": ["css/swagger._-APWT_3.css"] | ||
| }, | ||
| "web_src/css/themes/theme-gitea-dark.css": { | ||
| "file": "css/theme-gitea-dark.CyAaQnn5.css", | ||
| "name": "theme-gitea-dark", | ||
| "src": "web_src/css/themes/theme-gitea-dark.css", | ||
| "isEntry": true | ||
| }, | ||
| "web_src/js/features/sharedworker.ts": { | ||
| "file": "js/sharedworker.Dug1twio.js", | ||
| "name": "sharedworker", | ||
| "src": "web_src/js/features/sharedworker.ts", | ||
| "isEntry": true | ||
| }, | ||
| "_chunk.js": { | ||
| "file": "js/chunk.abc123.js", | ||
| "name": "chunk" | ||
| } | ||
| }`) | ||
|
|
||
| paths := parseManifest(manifest) | ||
|
|
||
| // JS entries | ||
| assert.Equal(t, "js/index.C6Z2MRVQ.js", paths["js/index.js"]) | ||
| assert.Equal(t, "js/swagger.SujiEmYM.js", paths["js/swagger.js"]) | ||
| assert.Equal(t, "js/sharedworker.Dug1twio.js", paths["js/sharedworker.js"]) | ||
|
|
||
| // Associated CSS from JS entries | ||
| assert.Equal(t, "css/index.B3zrQPqD.css", paths["css/index.css"]) | ||
| assert.Equal(t, "css/swagger._-APWT_3.css", paths["css/swagger.css"]) | ||
|
|
||
| // CSS-only entries | ||
| assert.Equal(t, "css/theme-gitea-dark.CyAaQnn5.css", paths["css/theme-gitea-dark.css"]) | ||
|
|
||
| // Non-entry chunks should not be included | ||
| assert.Empty(t, paths["js/chunk.js"]) | ||
| } | ||
|
|
||
| func TestGetAssetPathFallback(t *testing.T) { | ||
| // When manifest is not loaded, GetAssetPath should return the input as-is | ||
| manifestMu.Lock() | ||
| old := manifestPaths | ||
| manifestPaths = make(map[string]string) | ||
| manifestMu.Unlock() | ||
| defer func() { | ||
| manifestMu.Lock() | ||
| manifestPaths = old | ||
| manifestMu.Unlock() | ||
| }() | ||
|
|
||
| assert.Equal(t, "js/index.js", GetAssetPath("js/index.js")) | ||
| assert.Equal(t, "css/theme-gitea-dark.css", GetAssetPath("css/theme-gitea-dark.css")) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.