-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
[Experimental Feedback] Exclude webextension-polyfill
via extensionApi: "chrome"
#868
Comments
import type { Commands } from "wxt/browser"; Is there a way to make code like this take advantage of the types in |
@aiktb If you installed function registerCommand(command: chrome.commands.Command) {
// ...
} Because of the way the |
Will test it out in my extension in a few and report back issues if I encounter them |
Tested and works just fine! |
Tested and works me too. If there's anything that have an impact at runtime, let me know, and I'll test it. |
tested, works fine too :) |
extensionApi: "chrome"
webextension-polyfill
via extensionApi: "chrome"
What about aliasing |
So there's two approaches:
If you want to fully remove the polyfill from all dependencies, you can setup the alias yourself: // wxt.config.ts
export default defineConfig({
vite: () => ({
alias: {
'webextension-polyfill': path.resolve('polyfill-replacement.ts'),
},
ssr: {
noExternal: ['@webext-core/storage']
},
}),
});
// polyfill-replacement.ts
import { browser } from 'wxt/browser/chrome';
export default browser; But be aware this can break any dependencies that rely on polyfill-specific behaviors. This WAS the behavior with the old experimental option before this one, but I changed it to just remove the polyfill from WXT to avoid breaking other dependencies. |
@aklinker1 think I've found a bug with type generation using this feature:
FYI I'm on the latest TS version as of now (5.6.2). |
@joealden I also had a similar issue in one of my work repos. The problem was that I wasn't extending the So make sure either it's extended in your tsconfig: {
"extends": "./.wxt/tsconfig.json"
} or make sure to include /// <reference types="./.wxt/wxt.d.ts" /> |
@aklinker1 thanks! Is that documented (as I presume it'd not specific to |
I have it documented in a big rewrite I'm doing: https://github.com/wxt-dev/wxt/blob/docs-structure-update/docs/guide/config/typescript.md Will add the part about the declaration file though. |
Fantastic upgrade strategy and the webextension-polyfill situation handling in general @aklinker1 🎖️ Reporting no issues in a simple project, will follow up once it grows ✔️ |
Seems like this is working well for people, I'm gonna enable |
I might have forgotten to give my input on this. Using it in latest release of my extension for Chrome and Firefox. Working flawlessly for ~60k users. |
@aklinker1 We found a problem about the |
Huh, weird... https://github.com/wxt-dev/wxt/blob/main/packages%2Fwxt%2Fpackage.json#L85 Quick fix, let's add the dependency to the templates for now. |
Triple slash directives are removed at Agree to include it in the dependencies as a workaround for now. |
@aklinker1 I submitted workaround PR. #1119 |
could you please elaborate on what is meant with "include somewhere else"? The So not sure if I understand it correctly, but I've put it into the root tsconfig.base.json as
Haven't had any issues so far, other than IntelliJ-related issues with linting, so I guess it's not totally wrong |
https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html It means to include that directive somewhere at the global level. |
Thanks. To be honest using this feels totally wrong. Is there any reason why it can't be added via
Looks that it does what it should and its much cleaner than putting these references in files other than tsconfig But maybe I'm missing the point here... |
Yup, that works too. I only recommend references because that way you don't have to worry about merging your |
v0.19.0 introduced a new option for excluding the
webextension-polyfill
.Setup
wxt.config.ts
with the new feature flag:@types/chrome
, the package providing types when using the chrome API. It provides more up-to-date types with much better support for MV3 features.browser
imports.Testing
wxt prepare
before this)Note
If you have any feedback, problems, type errors, or runtime issues, please share them below so I can get them fixed. Goal is to ship this option as the default in the next major version,
v0.20.0
The text was updated successfully, but these errors were encountered: