You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/resources/upgrading.md
+238Lines changed: 238 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,7 @@
1
+
---
2
+
outline: deep
3
+
---
4
+
1
5
# Upgrading WXT
2
6
3
7
## Overview
@@ -12,6 +16,240 @@ Listed below are all the breaking changes you should address when upgrading to a
12
16
13
17
Currently, WXT is in pre-release. This means changes to the second digit, `v0.X`, are considered major and have breaking changes. Once v1 is released, only major version bumps will have breaking changes.
14
18
19
+
## v0.19.0 → v0.20.0
20
+
21
+
v0.20 is a big release! There are lots of breaking changes because this version is intended to be a release candidate for v1.0. If all goes well, v1.0 will be released with no additional breaking changes.
22
+
23
+
:::warning
24
+
Read through all the changes before updating your extension.
25
+
:::
26
+
27
+
### `webextension-polyfill` Removed
28
+
29
+
Since MV3 and the deprecation of MV2 by Chrome in June 2024, the `webextension-polyfill` doesn't really serve a purpose anymore. In WXT, all it did was polyfill the promise-based API for Chrome MV2.
30
+
31
+
As such, WXT no longer supports the polyfill and the `extensionApi` config has been removed.
32
+
33
+
```ts
34
+
// wxt.config.ts
35
+
exportdefaultdefineConfig({
36
+
extensionApi: 'chrome', // [!code --]
37
+
});
38
+
```
39
+
40
+
If you were using `extensionApi: 'chrome'`, this is the default now! Remove it from your config and you're good to go.
41
+
42
+
If you weren't using `extensionApi: 'chrome'`, `wxt/browser` has changed. Now, it re-exports the `chrome` global for Chromium or the `browser` global for Firefox and Safari. However, most of the time no code changes are required, the API behaves the same at runtime. Continue importing `browser` from WXT:
43
+
44
+
```ts
45
+
import { browser } from'wxt/browser';
46
+
```
47
+
48
+
#### Extension API Types
49
+
50
+
Type definitions are now provided by `@types/chrome` instead of `@types/webextension-polyfill`. `@types/chrome` is more up-to-date with the latest MV3 APIs, while still supporting MV2.
51
+
52
+
If you're importing types, they are not named exports anymore. Instead, types are accessed directly off the `browser` variable.
Be aware the `@types/chrome` and `@types/webextension-polyfill` use different names and may have different types for some APIs. If you get a type-error, fix it.
68
+
:::
69
+
70
+
### `public/` and `modules/` Directories Moved
71
+
72
+
The default location for the `public/` and `modules/` directories have changed to better align with standards set by other frameworks (Nuxt, Next, Astro, etc.). Now, each path is relative to the root directory.
73
+
74
+
- `<srcDir>/public` → `<root>/public`
75
+
- `<srcDir>/modules` → `<root>/modules`
76
+
77
+
If you follow the default folder structure, you don't need to make any changes.
78
+
79
+
If you set a custom `srcDir`, you have two options:
80
+
81
+
1. Keep the folders in the same place and update your project config:
82
+
```ts
83
+
// wxt.config.ts
84
+
exportdefaultdefineConfig({
85
+
srcDir: 'src',
86
+
publicDir: 'src/public', // [!code ++]
87
+
modulesDir: 'src/modules', // [!code ++]
88
+
});
89
+
```
90
+
2. Move the your `public/` and `modules/` directories to the project root:
91
+
```diff
92
+
<root>/
93
+
+modules/
94
+
+public/
95
+
src/
96
+
components/
97
+
entrypoints/
98
+
-modules/
99
+
-public/
100
+
utils/
101
+
wxt.config.ts
102
+
```
103
+
104
+
### Import Path Changes
105
+
106
+
If you are manually importing `wxt/sandbox`, `wxt/client`, or `wxt/storage`, their APIs have been moved. Now, each API gets it's own submodule inside `wxt/utils/*`. This improves treeshaking, reduces bundle size, and better prepares WXT for adding more utilities in the future.
107
+
108
+
:::details New import paths
109
+
110
+
<!-- prettier-ignore -->
111
+
```ts
112
+
import { useAppConfig } from 'wxt/utils/app-config';
113
+
import { ContentScriptContext } from 'wxt/utils/content-script-context';
114
+
import { createIframeUi } from 'wxt/utils/content-script-ui/iframe';
115
+
import { createIntegratedUi } from 'wxt/utils/content-script-ui/integrated';
116
+
import { createShadowRootUi } from 'wxt/utils/content-script-ui/shadow-root';
117
+
import { defineAppConfig } from 'wxt/utils/define-app-config';
118
+
import { defineBackground } from 'wxt/utils/define-background';
119
+
import { defineContentScript } from 'wxt/utils/define-content-script';
120
+
import { defineUnlistedScript } from 'wxt/utils/define-unlisted-script';
121
+
import { defineWxtPlugin } from 'wxt/utils/define-wxt-plugin';
122
+
import { injectScript } from 'wxt/utils/inject-script';
123
+
import { InvalidMatchPattern, MatchPattern } from 'wxt/utils/match-patterns';
124
+
import { MigrationError, storage } from 'wxt/utils/storage';
125
+
```
126
+
127
+
:::
128
+
129
+
However, that's a lot of new paths to learn. That why WXT is also introducing the new [`#imports` module](/guide/essentials/config/auto-imports#explicit-imports-imports)! Instead of using the new import paths, just import the APIs from `#imports` instead:
130
+
131
+
<!-- prettier-ignore -->
132
+
```ts
133
+
import { storage } from 'wxt/storage'; // [!code --]
134
+
import { defineContentScript } from 'wxt/sandbox'; // [!code --]
135
+
import { ContentScriptContext, useAppConfig } from 'wxt/client'; // [!code --]
136
+
import { // [!code ++]
137
+
storage, // [!code ++]
138
+
defineContentScript, // [!code ++]
139
+
ContentScriptContext, // [!code ++]
140
+
useAppConfig, // [!code ++]
141
+
} from '#imports'; // [!code ++]
142
+
```
143
+
144
+
> If you want to see where all the efer to the [API reference](/api/reference/wxt) or your project's `.wxt/types/imports-module.d.ts` file if you're curious.
145
+
146
+
When bundled, any imports from `#imports` will be broken up and replace with individual imports to the new submodules.
147
+
148
+
:::tip
149
+
Before types will work, you'll need to run `wxt prepare` to generate the TypeScript declarations.
150
+
:::
151
+
152
+
Read more about the new `#imports` module in the [blog post](/blog/2024-12-06-using-imports-module).
153
+
154
+
### `createShadowRootUi` CSS Changes
155
+
156
+
WXT now blocks inherited styles from the webpage (`visibility`, `color`, `font-size`, etc.) by setting `all: initial` inside the shadow root.
157
+
158
+
If you use `createShadowRootUI`, double check that your UIs are styled properly. If you have any manual CSS resets to override a page style, you can remove them:
> This doesn't effect `rem` units. You should continue using `postcss-rem-to-px` or an equivalent library if the webpage sets the HTML element's `font-size`.
170
+
171
+
If you run into problems with the new behavior, you can disable it and continue using your current CSS:
172
+
173
+
```ts
174
+
const ui =awaitcreateShadowRootUi({
175
+
inheritStyles: true, // [!code ++]
176
+
// ...
177
+
});
178
+
```
179
+
180
+
### Default Build Output Directories Changed
181
+
182
+
The build mode is now apart of the output directory:
> The optional changes will be deprecated in the future.
224
+
225
+
This improves the consistency with the config's filename, `web-ext.config.ts`.
226
+
227
+
If you continue using `runner` or `defineRunnerConfig`, WXT will log an warning, but it will still work until the next major version.
228
+
229
+
### Load Config as ESM
230
+
231
+
Upgraded `c12` to v2 and now `wxt.config.ts` and `web-ext.config.ts` are loaded as true ESM modules. If you're using any CJS APIs, like `__filename` or `__dirname`, replace them with their ESM counterparts, like `import.meta.filename` or `import.meta.dirname`.
232
+
233
+
### Deprecated APIs Removed
234
+
235
+
- `entrypointLoader` option: WXT now uses `vite-node` for importing entrypoints during the build process.
236
+
> This was deprecated in v0.19.0, see the [v0.19 section](#v0-18-5-rarr-v0-19-0) for migration steps.
237
+
- `transformManifest` option: Use the `build:manifestGenerated` hook to transform the manifest instead:
0 commit comments