Restructuring Project Directory for Better Organization #1161
-
After reviewing the documentation, I noticed the current directory structure:
I have two main concerns:
These changes could potentially improve code organization and maintainability. I'd appreciate your thoughts on these suggestions and any reasons for the current structure. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can import code from other files in your background, so no, it doesn't have to be a single file. You can also use a folder for the background and put related files in that folder, see https://wxt.dev/guide/essentials/entrypoints.html#background // entrypoints/background/index.ts
import { initAlarms } from './alarms'
import { initMessaging } from './messaging'
export default define background(() => {
initMessaging()
initAlarms()
// ...
}) // entrypoints/background/alarms.ts
export function initAlarms() {
// ...
} // entrypoints/background/messaging.ts
export function initMessaging() {
// ...
} Also see #1038, someone has opened an issue for letting WXT discover multiple files rather than requiring you to import all the files you want to init.
There's been discussion around this in the past but no one has made a compelling enough argument for a different structure. See #192 (comment) |
Beta Was this translation helpful? Give feedback.
You can import code from other files in your background, so no, it doesn't have to be a single file. You can also use a folder for the background and put related files in that folder, see https://wxt.dev/guide/essentials/entrypoints.html#background
Also see #1038, someone has opened an issue fo…