If we create an extension which has multiple entrypoints but use the same resource, the build will fail.
For example if we have Firefox plugin with browser_action and sidebar_action and use the same popup.html the build will fail with error Entrypoint output for popup.html (popup.html) not found.
Reproduction
Steps to reproduce:
Create new web extension using command npm create vite-plugin-web-extension
Edit manifest.json and add:
"{{firefox}}.sidebar_action": {
"default_title": "My sidebar",
"default_panel": "popup.html",
"default_icon": "icon/48.png"
}
Open vite.config.ts and set webExtension's browser config to firefox.
Run npm run build
Result:
[web-extension:manifest] Entrypoint output for popup.html (popup.html) not found
error during build:
Error: Entrypoint output for popup.html (popup.html) not found
at findReplacement (file:///C:/Users/abcdx/reproducer/node_modules/vite-plugin-web-extension/dist/index.js:959:11)
at replaceEntrypoint (file:///C:/Users/abcdx/reproducer/node_modules/vite-plugin-web-extension/dist/index.js:970:43)
at renderManifest (file:///C:/Users/abcdx/reproducer/node_modules/vite-plugin-web-extension/dist/index.js:936:3)
at buildExtension (file:///C:/Users/abcdx/reproducer/node_modules/vite-plugin-web-extension/dist/index.js:1057:30)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.buildStart (file:///C:/Users/abcdx/reproducer/node_modules/vite-plugin-web-extension/dist/index.js:1137:9)
at async Promise.all (index 5)
at async PluginDriver.hookParallel (file:///C:/Users/abcdx/reproducer/node_modules/rollup/dist/es/shared/node-entry.js:25260:9)
at async file:///C:/Users/abcdx/reproducer/node_modules/rollup/dist/es/shared/node-entry.js:26484:13
at async catchUnfinishedHookActions (file:///C:/Users/abcdx/reproducer/node_modules/rollup/dist/es/shared/node-entry.js:25698:16)
The splice method will remove the element from generatedFiles array (and bundles[entry]). So if another entry use the same resource it will throw error because the element is already removed.
Summary
If we create an extension which has multiple entrypoints but use the same resource, the build will fail.
For example if we have Firefox plugin with
browser_action
andsidebar_action
and use the samepopup.html
the build will fail with errorEntrypoint output for popup.html (popup.html) not found
.Reproduction
Steps to reproduce:
npm create vite-plugin-web-extension
manifest.json
and add:vite.config.ts
and set webExtension's browser config to firefox.npm run build
Environment
Possible Cause & Fix
I believe the culprit is this line: https://github.com/aklinker1/vite-plugin-web-extension/blob/3bad9ebd057b10d6fc2aa9ce43508f1600b8ccc0/packages/vite-plugin-web-extension/src/build/renderManifest.ts#L64
The splice method will remove the element from generatedFiles array (and bundles[entry]). So if another entry use the same resource it will throw error because the element is already removed.
Possible fix is to use slice method instead: