-
Notifications
You must be signed in to change notification settings - Fork 535
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
Introduce vite to transpile js/css assets for development and production + vitest for static file testing #22957
Conversation
6ec5e0b
to
a33c53e
Compare
de7b184
to
ab67362
Compare
ec121bb
to
2f87f8d
Compare
2f87f8d
to
05fb444
Compare
433e8fc
to
75d2dc4
Compare
75d2dc4
to
67c2dbb
Compare
STATIC_BUILD_PATH = path('static-build') | ||
# This value should be kept in sync with vite.config.js | ||
# where the manifest will be written to | ||
STATIC_BUILD_MANIFEST_PATH = path(STATIC_BUILD_PATH, 'manifest.json') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit unfortunate that vite
calls this manifest.json
, same as webextensions manifest, but at least it doesn't conflict with django's staticfiles.json
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can make the file whatever we want. I could make it "vite-manifest.json" or "banana.json" as long as the file names are aligned in both places it's up to us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relates to: mozilla/addons#2000
Description
Note
Don't be scared, most of the changes are package-lock.json
preload.js
andanalytics.js
scripts initially.Context
This PR introduces the "plumbing" needed for compiling assets with vite. It does not migrate all assets to using vite. We should split this up after landing this and we can move assets over to esm with vite.
Vite
Vite will now compile every file in
./static/js/*.js
and./static/cs/*.less
into independent bundles. Those files can then be included in our django app via the helper methodvite_asset
.For example:
This will render roughly to this:
In development mode,
vite_asset_url
will resolve to/static/bundle/<path>
where path is the original path to the url.Nginx routes
/static/bundle/
to the vite dev server which will then return the asset compiled in real time. LESS will return CSS and JS will return transpiled js.In production mode, vite will compile the assets and save them in
./site-static/assets/
and a manifest will be used to resolve the url to the file path. Nginx will mount this path and serve files directly. In production environments, like before we will serve files from a CDN.Testing
Dev mode
Run the dev/prod version of the app and make sure that:
Prod mode
Automated tests
Run the following tests which are now using vitest instead of jest
make test_setup
make run_js_tests
Checklist
#ISSUENUM
at the top of your PR to an existing open issue in the mozilla/addons repository.