Skip to content

Commit d87892e

Browse files
committed
docs: Update v0.20 upgrade docs
1 parent 763641c commit d87892e

File tree

2 files changed

+34
-59
lines changed

2 files changed

+34
-59
lines changed

docs/guide/resources/upgrading.md

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,58 +26,58 @@ Read through all the changes once before making any code changes.
2626

2727
### `webextension-polyfill` Removed
2828

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.
3032

3133
To upgrade, you have two options:
3234

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):
3738
```sh
3839
pnpm i webextension-polyfill @wxt-dev/webextension-polyfill
3940
```
4041
- Add the WXT module to your config:
41-
```ts
42-
// wxt.config.ts
42+
```ts [wxt.config.ts]
4343
export default defineConfig({
4444
modules: ['@wxt-dev/webextension-polyfill'],
4545
});
4646
```
4747

4848
Regardless of your choice, the `extensionApi` config has been removed. Remove it from your `wxt.config.ts` file if present:
4949

50-
```ts
51-
// wxt.config.ts
50+
```ts [wxt.config.ts]
5251
export default defineConfig({
5352
extensionApi: 'chrome', // [!code --]
5453
});
5554
```
5655

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:
5859

5960
<!-- prettier-ignore -->
6061
```ts
6162
import type { Runtime } from 'wxt/browser'; // [!code --]
62-
import { browser } from 'wxt/browser'; // [!code ++]
63+
import type { Browser } from 'wxt/browser'; // [!code ++]
6364
6465
function getMessageSenderUrl(sender: Runtime.MessageSender): string { // [!code --]
65-
function getMessageSenderUrl(sender: browser.runtime.MessageSender): string { // [!code ++]
66+
function getMessageSenderUrl(sender: Browser.runtime.MessageSender): string { // [!code ++]
6667
// ...
6768
}
6869
```
6970
70-
`@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.
7172
7273
### `public/` and `modules/` Directories Moved
7374
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.
7576
7677
- If you follow the default folder structure, you don't need to make any changes.
7778
- If you set a custom `srcDir`, you have two options:
7879
1. Keep the folders in the same place and update your project config:
79-
```ts
80-
// wxt.config.ts
80+
```ts [wxt.config.ts]
8181
export default defineConfig({
8282
srcDir: 'src',
8383
publicDir: 'src/public', // [!code ++]
@@ -128,11 +128,10 @@ WXT now resets styles inherited from the webpage (`visibility`, `color`, `font-s
128128
If you use `createShadowRootUi`:
129129
130130
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:
132132
133133
<!-- prettier-ignore -->
134-
```css
135-
/* entrypoints/reddit.content/style.css */
134+
```css [entrypoints/reddit.content/style.css]
136135
body { /* [!code --] */
137136
/* Override Reddit's default "hidden" visibility on elements */ /* [!code --] */
138137
visibility: visible !important; /* [!code --] */
@@ -154,46 +153,30 @@ const ui = await createShadowRootUi({
154153
155154
### Default Output Directories Changed
156155
157-
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:
158157
159-
- `--mode production`: `.output/chrome-mv3` (unchanged)
160-
- `--mode development`: `.output/chrome-mv3-dev` (`-dev` suffix)
161-
- `--mode custom`: `.output/chrome-mv3-custom` (`-[mode]` suffix)
158+
- `--mode production` &rarr; `.output/chrome-mv3`: Production builds are unchanged
159+
- `--mode development` &rarr; `.output/chrome-mv3-dev`: Dev mode now has a `-dev` suffix so it doesn't overwrite production builds
160+
- `--mode custom` &rarr; `.output/chrome-mv3-custom`: Other custom modes end with a `-[mode]` suffix
162161
163-
To revert and use the old behavior, writing all output to the same directory, set `outDirTemplate` option:
162+
To use the old behavior, writing all output to the same directory, set `outDirTemplate` option:
164163
165-
```ts
166-
// wxt.config.ts
164+
```ts [wxt.config.ts]
167165
export default defineConfig({
168166
outDirTemplate: '{{browser}}-mv{{manifestVersion}}', // [!code ++]
169167
});
170168
```
171169
172-
If you've loaded the extension into your browser manually for development, uninstall and re-install it from the new dev output directory.
173-
174-
### Internal Auto-import Options Changed
175-
176-
Only relevant if you refer to WXT's built-in `preset`s in the `imports` config in a module or hooks.
177-
178-
Instead of using `package` to auto-detect APIs to auto-import, WXT now uses `from` and `imports` to manually list APIs that are imported.
179-
180-
```ts
181-
presets: [
182-
{ package: "wxt/browser" }, // [!code --]
183-
{ from: "wxt/browser": imports: ["browser"] }, // [!code --]
184-
// ...
185-
]
186-
```
187-
188-
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+
:::
189173
190174
### `runner` APIs Renamed
191175
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:
193177
194178
1. The `runner` option has been renamed to `webExt`:
195-
```ts
196-
// wxt.config.ts
179+
```ts [wxt.config.ts]
197180
export default defineConfig({
198181
runner: { // [!code --]
199182
webExt: { // [!code ++]
@@ -202,8 +185,7 @@ To improve consistency with the `web-ext.config.ts` file, the "runner" APIs have
202185
});
203186
```
204187
2. `defineRunnerConfig` has been renamed to `defineWebExtConfig`:
205-
```ts
206-
// web-ext.config.ts
188+
```ts [web-ext.config.ts]
207189
import { defineRunnerConfig } from 'wxt'; // [!code --]
208190
import { defineWebExtConfig } from 'wxt'; // [!code ++]
209191
```
@@ -213,20 +195,13 @@ To improve consistency with the `web-ext.config.ts` file, the "runner" APIs have
213195
import type { WebExtConfig } from 'wxt'; // [!code ++]
214196
```
215197
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-
222198
### Deprecated APIs Removed
223199
224200
- `entrypointLoader` option: WXT now uses `vite-node` for importing entrypoints during the build process.
225201
> This was deprecated in v0.19.0, see the [v0.19 section](#v0-18-5-rarr-v0-19-0) for migration steps.
226202
- `transformManifest` option: Use the `build:manifestGenerated` hook to transform the manifest instead:
227203
<!-- prettier-ignore -->
228-
```ts
229-
// wxt.config.ts
204+
```ts [wxt.config.ts]
230205
export default defineConfig({
231206
transformManifest(manifest) { // [!code --]
232207
hooks: { // [!code ++]
@@ -244,7 +219,7 @@ If you're using any CJS APIs, like `__filename` or `__dirname`, replace them wit
244219
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:
245220
246221
<!-- prettier-ignore -->
247-
```ts
222+
```ts [wxt.config.ts]
248223
export default defineConfig({
249224
vite: () => ({ // [!code ++]
250225
ssr: { // [!code ++]
@@ -292,7 +267,7 @@ Basically, you can now import and do things outside the `main` function of the e
292267
293268
To continue using the old approach, add the following to your `wxt.config.ts` file:
294269
295-
```ts
270+
```ts [wxt.config.ts]
296271
export default defineConfig({
297272
entrypointLoader: 'jiti', // [!code ++]
298273
});

packages/wxt/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "wxt",
33
"type": "module",
4-
"version": "0.19.29",
4+
"version": "0.20.0-beta2",
55
"description": "⚡ Next-gen Web Extension Framework",
66
"license": "MIT",
77
"scripts": {

0 commit comments

Comments
 (0)