-
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
One of WXT's main goals is to make it easy to create web extensions for all browsers, including firefox, which is why it uses So I don't plan on adding this. |
Beta Was this translation helpful? Give feedback.
-
You can do that! Nothing is stopping you from using You won't be able to remove the polyfill from the final bundles because it's used internally by WXT in production, so it will always be included in your final bundle. I would highly recommend using
Obviously though, you're free to use |
Beta Was this translation helpful? Give feedback.
-
I have no idea referencing in your screenshot, it's to zoomed in to tell. Is this a content script, background, or chunk? Also not sure if this is a production build or a dev build - WXT adds code to each, but the code it adds is different for each mode. Can you share the actual code, maybe just copy-paste the actual statements you're curious about? Personally, I don't worry too much about the size of a web extensions. All the files are loaded locally from the users file system, so it's OK if they're not perfectly optimized, unlike the web. Of course, WXT shouldn't include unnecessary bloat or malicious code, which it doesn't. If you want to review what WXT adds to your code, here are the links. Your entrypoint files are imported as |
Beta Was this translation helpful? Give feedback.
-
Big question with a long answer lol. TLDR: Reusing chunks like this across all entrypoints, while maybe possible from a technical perspective, has major limitations, would be very fragile, and would complicate the build process. So no, this is not something that is realistically possible. More detailsSo basically you want to enable code-splitting across all entrypoints (HTML pages, background, and content scripts) to share code between everything. While this is possible, it has some limitations, limitations I've decided are to great to support at this time. Currently, all HTML pages are built in a single step, and do share "chunks" of code used between them. These often include packages from node_modules, like you mention, but also any utilities used on multiple pages. So HTML files are already doing what you want. The background script is all bundled individually. So if you use code or libraries that are also used in HTML pages, they will be duplicated inside your background script. MV2 background pages do not support CJS or ESM formats, so MV2 backgrounds script have to be self contained and bundled individually. MV3 supports ESM service workers and could reuse the chunks generated by the HTML pages, but unfortunately, Rollup's chunking algorithm doesn't take into account that the background script doesn't have a As for content scripts, they do not support ESM, and thus cannot reuse chunks from the rest of the build, just like the background. There is a "hack" to use ESM in content scripts, but it has downsides. You could use a dynamic So to summarize. If you have an extension with two HTML pages (let's say a popup and options page), a background script, and one content script, any shared code will be present 3 times in your final bundle. You can verify this using |
Beta Was this translation helpful? Give feedback.
-
Thanks for all of the feedback here. It means a lot! I am bundle-phobic, did not know that it's irrelevant for the browser extension to worry about the size. That's why I was aiming to get rid of everything (all polyfills) and even forget about the frameworks that I enjoy working with, just to gain the minimal bundle as possible. Found out about Aside, I also wanted to make a tiny wrapper that would either use But now with your information, I think I should just go with I am kind of worried on one side here. I see that you are actively developing |
Beta Was this translation helpful? Give feedback.
I had not heard of arrow-js before, seems like a really cool project! You can definitely create a vanilla, no build step web extension, but the downsides there is that you won't be able to use NPM modules and the dev experience will be much slower without a custom dev mode. So if you want those, a bundler/framework is the only choice.
A valid concern. I have another project for building web extensions,
vite-plugin-w…