-
Notifications
You must be signed in to change notification settings - Fork 188
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
feat!: ESM background support #398
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #398 +/- ##
==========================================
+ Coverage 80.30% 80.35% +0.04%
==========================================
Files 107 107
Lines 7728 7761 +33
Branches 695 701 +6
==========================================
+ Hits 6206 6236 +30
- Misses 1506 1509 +3
Partials 16 16 ☔ View full report in Codecov by Sentry. |
src/core/builders/vite/index.ts
Outdated
// Place JS entrypoints in main directory without a hash. (popup.html & popup.js are next to each other) | ||
entryFileNames: '[name].js', |
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.
Breaking change to the build output format.
Before:
.output/
<target>/
chunks/
popup-<hash>.js
popup.html
After:
.output/
<target>/
popup.html
popup.js
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.
This change ensures the ESM background entrypoint (a JS file, not HTML), is output to the root of the build directory as well, just like the non-ESM background.
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.
@aklinker1 Is it possible to control the output path using wxt.config.ts?
To have one build for dev and prod.
So when I build for dev it doesn't overwrite previously built one for prod.
.output/
dev-chrome-mv3/
chunks/
popup-<hash>.js
popup.html
And also
.output/
prod-chrome-mv3/
chunks/
popup-<hash>.js
popup.html
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.
@lionelhorn In a hacky way, yes. You could set an environment variable, and reference it in the wxt.config.ts
file while setting the outDir
. WXT doesn't provide any options for changing the target directories inside the output directory.
DEV=true wxt
wxt build
// wxt.config.ts
import { defineConfig } from 'wxt';
export default defineConfig({
outDir: process.env.DEV === "true" ? ".output/.dev" : ".output"
});
This would give you something like:
.output/
.dev/
chrome-mv3/
firefox-mv2/
chrome-mv3/
firefox-mv2/
Adding
type: "module"
to the background script definition will cause it to be included in the ESM build along side any UIs. This speeds up development, reduces bundle size, and adds support things like WASM, which requires ES modules to load (this will address #392).Todo
type=module
type=module
is ignored for MV2