Skip to content

Commit 2f2cf76

Browse files
committed
docs: Add CRXJS migration docs
1 parent 342057b commit 2f2cf76

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

docs/guide/resources/migrate.md

+22-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ pnpm dlx wxt@latest init example-wxt --template vanilla
1818
In general, you'll need to:
1919

2020
&ensp;<input type="checkbox" /> Install `wxt`<br />
21-
&ensp;<input type="checkbox" /> [Extend `.wxt/tsconfig.json`](/guide/essentials/config/typescript.html#typescript-configuration) in your project's `tsconfig.json`<br />
21+
&ensp;<input type="checkbox" /> [Extend `.wxt/tsconfig.json`](/guide/essentials/config/typescript#typescript-configuration) in your project's `tsconfig.json`<br />
2222
&ensp;<input type="checkbox" /> Update/create `package.json` scripts to use `wxt` (don't forget about `postinstall`)<br />
2323
&ensp;<input type="checkbox" /> Move entrypoints into `entrypoints/` directory<br />
2424
&ensp;<input type="checkbox" /> Move assets into either the `assets/` or `public/` directories<br />
2525
&ensp;<input type="checkbox" /> Move `manifest.json` content into `wxt.config.ts`<br />
2626
&ensp;<input type="checkbox" /> Convert custom import syntax to be compatible with Vite<br />
2727
&ensp;<input type="checkbox" /> Add a default export to JS entrypoints (`defineBackground`, `defineContentScript`, or `defineUnlistedScript`)<br />
2828
&ensp;<input type="checkbox" /> Use the `browser` global instead of `chrome`<br />
29-
&ensp;<input type="checkbox" /> Compare final `manifest.json` files, making sure permissions and host permissions are unchanged<br/>
29+
&ensp;<input type="checkbox" /> ⚠️ Compare final `manifest.json` files, making sure permissions and host permissions are unchanged<br/>
3030
:::warning
3131
If your extension is already live on the Chrome Web Store, use [Google's update testing tool](https://github.com/GoogleChromeLabs/extension-update-testing-tool) to make sure no new permissions are being requested.
3232
:::
@@ -48,7 +48,25 @@ Here's specific steps for other popular frameworks/build tools.
4848
5. Convert Plasmo's custom import resolutions to Vite's
4949
6. If importing remote code via a URL, add a `url:` prefix so it works with WXT
5050
7. Replace your [Plasmo tags](https://docs.plasmo.com/framework/workflows/build#with-a-custom-tag) (`--tag`) with [WXT build modes](/guide/essentials/config/build-mode) (`--mode`)
51-
8. Compare your output `manifest.json` files from before the migration to after the migration. They should have the same content. If not, tweak your entrypoints and config to get as close as possible.
51+
8. ⚠️ Compare the old production manifest to `.output/*/manifest.json`. They should have the same content as before. If not, tweak your entrypoints and config until they are the same.
52+
53+
### CRXJS
54+
55+
If you used CRXJS's vite plugin, it's a simple refactor! The main difference between CRXJS and WXT is how the tools decide which entrypoints to build. CRXJS looks at your `manifest` (and vite config for "unlisted" entries), while WXT looks at files in the `entrypoints` directory.
56+
57+
To migrate:
58+
59+
1. Move all entrypoints into the `entrypoints` directory, refactoring to WXT's style (TS files have a default export).
60+
2. Move [entrypoint specific options out of the manifest](/guide/essentials/entrypoints#defining-manifest-options) and into the entrypoint files themselves (like content script `matches` or `run_at`).
61+
3. Move any other `manifest.json` options [into the `wxt.config.ts` file](/guide/essentials/config/manifest), like permissions.
62+
4. For simplicity, you'll probably want to [disable auto-imports](/guide/essentials/config/auto-imports#disabling-auto-imports) at first (unless you were already using them via `unimport` or `unplugin-auto-imports`). If you like the feature, you can enable it later once you've finished the migration.
63+
5. Update your `package.json` to include all of [WXT's suggested scripts (see step 4)](/guide/installation#from-scratch)
64+
6. Specifically, make sure you add the `"postinstall": "wxt prepare"` script to your `package.json`.
65+
7. Delete your `vite.config.ts` file. Move any plugins into the `wxt.config.ts` file. If you use a frontend framework, [install the relevant WXT module](/guide/essentials/frontend-frameworks).
66+
8. Update your typescript project. [Extend WXT's generated config](/guide/essentials/config/typescript), and [add any path aliases to your `wxt.config.ts` file](/guide/essentials/config/typescript#tsconfig-paths).
67+
9. ⚠️ Compare the old production manifest to `.output/*/manifest.json`. They should have the same content as before. If not, tweak your entrypoints and config until they are the same.
68+
69+
Here's an example migration: [GitHub Better Line Counts - CRXJS &rarr; WXT](https://github.com/aklinker1/github-better-line-counts/commit/39d766d2ba86866efefc2e9004af554ee434e2a8)
5270

5371
### `vite-plugin-web-extension`
5472

@@ -60,4 +78,4 @@ Since you're already using Vite, it's a simple refactor.
6078
4. Add `"postinstall": "wxt prepare"` script
6179
5. Move the `manifest.json` into `wxt.config.ts`
6280
6. Move any custom settings from `vite.config.ts` into `wxt.config.ts`'s
63-
7. Compare `dist/manifest.json` to `.output/*/manifest.json`, they should have the same content as before. If not, tweak your entrypoints and config to get as close as possible.
81+
7. ⚠️ Compare the old production manifest to `.output/*/manifest.json`. They should have the same content as before. If not, tweak your entrypoints and config until they are the same.

0 commit comments

Comments
 (0)