-
Notifications
You must be signed in to change notification settings - Fork 545
Use relative path resolution and manually include static assets in vite's module graph. #23209
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
Conversation
…te's module graph.
26048f9
to
b013dbf
Compare
b013dbf
to
0f246a9
Compare
In development mode, in devhub when looking at one of my add-ons, I got an error in the devtools console I've never seen before:
I repeated the entire clean process, went to |
Could you share here or on slack the contents of that file when you open the URL in the browser? It could be that the jquery global doesn't exist by the time we define $.cookie, but we have it injected in all bundles so would be odd. |
https://gist.github.com/diox/301acfb19f462e8e51bdebcf35ef5ba8 but my initial reaction was to switch to |
So it is including the jquery import and even hoisting correctly. However, I have noticed there can be some odd behavior around the jquery global. This could (potentially) be a race condition in the loading order of scripts. I don't have enough info to confirm that but we could consider isolating the jquery initialization script to it's own module, and (like in init.js) explicitly set it to a global. Throw that on the top of I'm leaning more towards a stale file being served due to one or another caching issue. With the number of changes it is unlikely there are zero bugs here, so we should probably have a ticket for that in case it happens again and then investigate further. |
Co-authored-by: Mathieu Pillard <[email protected]>
Fixes: mozilla/addons#15486
Description
Context
The path where we serve static assets impacts several parts of the codebase:
Since all of these have to be syncronized it makes sense to extract the part of the URL which defines the "root" or "prefix" of the url to its own environment variable setting.
By default, the values in
base_settings.py
will be the same, and these values are explicitly overriden in all production like environments. But in local environments this allows one to configure the path where static files are served from and linked to from a single place.Testing
clean project
Dev mode
Navigate the site, ensuring that static images, css files and js files are resolving correctly.
There are 141 URL imports in our css files, spread across virtually every page. It should be easy to find non-resolving URLs but make sure to be thorough and follow all links across devhub/reviewer tools
Prod mode
make down && make up DOCKER_TARGET=production
Expect the same as in dev mode. URLs should resolve correctly, though the css files will be bundled and minified.
Build
Verify the build is resolving correctly
Now inspect
./site-static/assets/css
, find a css file that imports filesdevhub.css
for example (note: it will have a hash postfix). Check for refrences tourl(
and expect all references should use relative paths pointing to../<path>
. This path should match a file existing at the expected path (in the parent).Note
Because vite transforms the file paths, nested files are collapsed so any file in source will point to
../<name>.<ext>
in the build. All css file as in<static>/css
and all images are in<static>/<name>.<ext>
so all css files will point to the parent directory when referencing static images.Dynamic STATIC_URL
Re-run the development build setting a value for the
STATIC_URL_PREFIX
Important
Make sure to include the
/
trailing slash.This will modify the path we expect to serve static files from for
nginx
,web
andstatic
(vite)Checklist
#ISSUENUM
at the top of your PR to an existing open issue in the mozilla/addons repository.