WXT should bundle multiple `background.js` scripts like it does with `content.js`
Feature Request
Currently it is easy to modularize the content scripts in the entrypoints folder by simply appending .content.ts to the file name.
Add the same ability to background.js.
Is your feature request related to a bug?
N/A
What are the alternatives?
From @aaronklinker-st :
For now, a quick fix to using multiple background scripts is to use Vite's glob import:
// background/index.ts
const scripts = import.meta.glob<{ default: () => void }>('./*.background.ts', { eager: true });
export default defineBackground(() => {
Object.values(scripts).map(script => script.default.main());
});
Then put your other files in like background/some-name.background.ts
Additional context
https://discord.com/channels/1212416027611365476/1290896813850886197
But isn't manifest version 3 only takes one script for service_worker?
Also,
Above screenshot will supposedly take all the entrypoints. But how to modularize this into one single file?
Cause rollup will create separate files each background files even if we use getLibModeConfig or getMultiPageConfig functions of vite builder?
We just need to update the virtual entrypoint to support multiple files. Right now it only supports one:
https://github.com/wxt-dev/wxt/blob/main/packages/wxt/src/virtual/background-entrypoint.ts
This is the file we actually bundle into the single background script.