-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Enable Webpack ESM output and move assets to /assets/
without subdirectories
#25940
Conversation
This has an interaction with #25907, so that one should merge first after which I will move the output directory to |
Needs updates now that #25907 is in. |
* main: Refactor "Content" for file uploading (go-gitea#25851) Fix SSPI auth panic (go-gitea#25955) Make pending commit status yellow again (go-gitea#25935) Move public asset files to the proper directory (go-gitea#25907) Disallow dangerous url schemes (go-gitea#25960) Avoid creating directories when loading config (go-gitea#25944) [skip ci] Updated translations via Crowdin
This is ready. I could not reproduce the strict mode violation that I previously saw with vite, so maybe it was something vite-specific. |
/static/
asset directory/assets/
without subdirectories
The strict mode-related error currently shows up on @wxiaoguang if you have any suggestions to fix it and improve this hacky error handler, please go ahead. We really shouldn't need to fake an |
Some code like |
WIP again because of #25940 (comment). Maybe we can't actually do ESM for the webcomponents because of that flicker. |
178538c appears to work to avoid the flicker. I do realize it's not ideal to load a module script as non-module, but it should work as long as we don't do |
Found a way to extract the devtest css again, so nothing from devtest should load in prod build again. |
As per this, combining |
There is another consideration with
This would introduce additional issues for people who host assets on another domain. While I discourage this as it's unnecessary since HTTP2, it's a breaking change to them. I have a feeling this change of script type is not worth it, at least not yet. |
Then I guess it breaks |
It could only work if said CDN would emit CORS headers, e.g. If offloading the gitea web server from asset requests is the goal, the |
If this does not land, we should use esbuild banner feature to run all JS in strict mode: evanw/esbuild#422 (comment) |
I haven't tested or fully understood the CDN problem. If it breaks CDN behavior, it would be a problem for many instances which depend on CDN ...... sorry I can't comment at the moment. (ps: CDN is not just for a "different domain", it also for network speed, cost, server bandwidth, etc) |
I think long-term, we eventually have to move to ESM script output to remove this unnecessary translation to CommonJS that webpack does. The question is just "when", not "if" imho. Maybe we should wait til the ESM feature stabilizes in webpack, but I imagine it won't be until webpack 6, if that ever comes. |
Extract from #25940. `assetUrlPrefix` is guaranteed to not contain trailing slashes, making this function unneeded.
Extract from #25940 and because #26743 does seem to need more work. This will be required if we are to run our JS in [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode). Previously, the two variables `$fields` and `$dirtyForms` polluted `window`: <img width="1145" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/e0270a0e-b881-4ed7-9cc4-e9ab25c0a2bc">
Not going to continue here for now. Maybe another try later. |
Enable Webpack to output ESM aka. modules. This is still flagged experimental, but in my testing, it works pretty well. With ESM, all the JS now runs in strict mode which has potential to bring up new JS errors. Also I consolidated the entrypoint scripts to single files because this is required anyways for a future migration to Vite. jQuery.are-you-sure is moved to a vendor file because it is not compatible with strict mode.
I noticed Webpack had some issues with lazy-loading the PNG from monaco, and I concluded that it's not worth to maintain the js,css,fonts etc subdirectories, so I moved the assets to a single subdirectory
static
which is also what vite does and it eliminates this class of webpack errors.This works quite well in my testing, but I'm putting WIP because I think there i a strict mode violation in
bootstrap.js
which is only triggered on error, so I'll investigate that later.