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
+33-58Lines changed: 33 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,58 +26,58 @@ Read through all the changes once before making any code changes.
26
26
27
27
### `webextension-polyfill` Removed
28
28
29
-
WXT no longer uses the `webextension-polyfill` internally and `wxt/browser` uses the `chrome`/`browser` globals provided by the browser.
29
+
WXT no longer uses the `webextension-polyfill`!
30
+
31
+
Why? The polyfill doesn't add any value anymore. WXT's new `browser` supports the promise-based APIs on all browsers/manifest versions and all shared APIs behave the same way.
30
32
31
33
To upgrade, you have two options:
32
34
33
-
1.**Stop using the polyfill**
34
-
- Replace any manual imports from `wxt/browser/chrome` with `wxt/browser`
35
-
2.**Continue using the polyfill**
36
-
- Install the polyfill and WXT's [new polyfill module](https://www.npmjs.com/package/@wxt-dev/webextension-polyfill):
35
+
1.**Stop using the polyfill** - No changes necessary, though you may want to do some manual testing to make sure everything continues to work. None of the early testers of this feature reported any runtime issues once they stopped using the polyfill.
36
+
2.**Continue using the polyfill** - If you want to keep using the polyfill, you can! One less thing to worry about during this upgrade.
37
+
- Install `webextension-polyfill` and WXT's [new polyfill module](https://www.npmjs.com/package/@wxt-dev/webextension-polyfill):
37
38
```sh
38
39
pnpm i webextension-polyfill @wxt-dev/webextension-polyfill
39
40
```
40
41
- Add the WXT module to your config:
41
-
```ts
42
-
// wxt.config.ts
42
+
```ts [wxt.config.ts]
43
43
export default defineConfig({
44
44
modules: ['@wxt-dev/webextension-polyfill'],
45
45
});
46
46
```
47
47
48
48
Regardless of your choice, the `extensionApi` config has been removed. Remove it from your `wxt.config.ts` file if present:
49
49
50
-
```ts
51
-
// wxt.config.ts
50
+
```ts [wxt.config.ts]
52
51
export default defineConfig({
53
52
extensionApi: 'chrome', // [!code --]
54
53
});
55
54
```
56
55
57
-
Additionally, extension API types have changed. `wxt/browser` now uses types from `@types/chrome` instead of `@types/webextension-polyfill`. You will have to migrate any type imports to use `@types/chrome`'s namespace approach:
56
+
Additionally, how you consume extension API types have changed. `wxt/browser` now uses types based on `@types/chrome` instead of `@types/webextension-polyfill`.
57
+
58
+
Types are now accessed off the `Browser` namespace:
58
59
59
60
<!-- prettier-ignore -->
60
61
```ts
61
62
import type { Runtime } from 'wxt/browser'; // [!code --]
62
-
import { browser } from 'wxt/browser'; // [!code ++]
63
+
import type { Browser } from 'wxt/browser'; // [!code ++]
`@types/chrome` are more up-to-date, contain less bugs, and don't have any auto-generated names. So even if you continue to use the polyfill, you will need to update your types to use these types.
71
+
These new types contain up-to-date MV3 APIs, contain less bugs, and don't have any auto-generated names.
71
72
72
73
### `public/` and `modules/` Directories Moved
73
74
74
-
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 project's root directory.
75
+
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 project's root directory, not the src directory.
75
76
76
77
- If you follow the default folder structure, you don't need to make any changes.
77
78
- If you set a custom `srcDir`, you have two options:
78
79
1. Keep the folders in the same place and update your project config:
79
-
```ts
80
-
// wxt.config.ts
80
+
```ts [wxt.config.ts]
81
81
export default defineConfig({
82
82
srcDir: 'src',
83
83
publicDir: 'src/public', // [!code ++]
@@ -128,11 +128,10 @@ WXT now resets styles inherited from the webpage (`visibility`, `color`, `font-s
128
128
If you use `createShadowRootUi`:
129
129
130
130
1. Double check that your UI looks the same as before.
131
-
2. If you have any manual CSS resets to override a page style, you can remove them:
131
+
2. If you have any manual CSS resets to these styles, you can remove them. For example:
132
132
133
133
<!-- prettier-ignore -->
134
-
```css
135
-
/* entrypoints/reddit.content/style.css */
134
+
```css [entrypoints/reddit.content/style.css]
136
135
body { /* [!code --] */
137
136
/* Override Reddit's default "hidden" visibility on elements */ /* [!code --] */
The default value for [`outDirTemplate`](/api/reference/wxt/interfaces/InlineConfig#outdirtemplate) has changed. Now, different build modes are output to different directories:
156
+
The default value for the [`outDirTemplate`](/api/reference/wxt/interfaces/InlineConfig#outdirtemplate) config has changed. Now, different build modes are output to different directories:
See [PR #1315 `packages/wxt/src/core/resolve-config.ts` changes](https://github.com/wxt-dev/wxt/pull/1315/files#diff-ff0465c3a486d3ba187204149a25fc8f632c44d65da356dc04c0f2b268a71506) for exact changes made.
170
+
:::warning
171
+
If you've previously loaded the extension into your browser manually for development, you'll need to uninstall and re-install it from the new dev output directory.
172
+
:::
189
173
190
174
### `runner` APIs Renamed
191
175
192
-
To improve consistency with the `web-ext.config.ts` file, the "runner" APIs have been renamed. You can continue using the old names, but they have been deprecated and will be removed in a future version:
176
+
To improve consistency with the `web-ext.config.ts`filename, the "runner"API and config options have been renamed. You can continue using the old names, but they have been deprecated and will be removed in a future version:
193
177
194
178
1. The `runner` option has been renamed to `webExt`:
195
-
```ts
196
-
// wxt.config.ts
179
+
```ts [wxt.config.ts]
197
180
export default defineConfig({
198
181
runner: { // [!code --]
199
182
webExt: { // [!code ++]
@@ -202,8 +185,7 @@ To improve consistency with the `web-ext.config.ts` file, the "runner" APIs have
202
185
});
203
186
```
204
187
2. `defineRunnerConfig` has been renamed to `defineWebExtConfig`:
205
-
```ts
206
-
// web-ext.config.ts
188
+
```ts [web-ext.config.ts]
207
189
import { defineRunnerConfig } from 'wxt'; // [!code --]
208
190
import { defineWebExtConfig } from 'wxt'; // [!code ++]
209
191
```
@@ -213,20 +195,13 @@ To improve consistency with the `web-ext.config.ts` file, the "runner" APIs have
213
195
import type { WebExtConfig } from 'wxt'; // [!code ++]
214
196
```
215
197
216
-
### Load Config as ESM
217
-
218
-
`wxt.config.ts` and `web-ext.config.ts` are now loaded as ESM modules. Previously, they were loaded as CJS.
219
-
220
-
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`.
221
-
222
198
### Deprecated APIs Removed
223
199
224
200
- `entrypointLoader` option: WXT now uses `vite-node`for importing entrypoints during the build process.
225
201
> This was deprecated in v0.19.0, see the [v0.19 section](#v0-18-5-rarr-v0-19-0) for migration steps.
226
202
- `transformManifest` option: Use the `build:manifestGenerated` hook to transform the manifest instead:
227
203
<!-- prettier-ignore -->
228
-
```ts
229
-
// wxt.config.ts
204
+
```ts [wxt.config.ts]
230
205
export default defineConfig({
231
206
transformManifest(manifest) { // [!code --]
232
207
hooks: { // [!code ++]
@@ -244,7 +219,7 @@ If you're using any CJS APIs, like `__filename` or `__dirname`, replace them wit
244
219
The default entrypoint loader has changed to `vite-node`. If you use any NPM packages that depend on the `webextension-polyfill`, you need to add them to Vite's `ssr.noExternal` option:
245
220
246
221
<!-- prettier-ignore -->
247
-
```ts
222
+
```ts [wxt.config.ts]
248
223
export default defineConfig({
249
224
vite: () => ({ // [!code ++]
250
225
ssr: { // [!code ++]
@@ -292,7 +267,7 @@ Basically, you can now import and do things outside the `main` function of the e
292
267
293
268
To continue using the old approach, add the following to your `wxt.config.ts` file:
0 commit comments