安装
引导一个新项目、从头开始,或迁移现有项目。
引导项目
运行init
命令,并按照提示操作。
sh
pnpm dlx wxt@latest init
sh
bunx wxt@latest init
sh
npx wxt@latest init
sh
# 初始使用 NPM,但提示时选择 Yarn
npx wxt@latest init
演示
运行 dev
命令后,继续后续步骤!
从头开始
创建新项目
shcd my-project pnpm init
shcd my-project bun init
shcd my-project npm init
shcd my-project yarn init
安装 WXT:
shpnpm i -D wxt
shbun i -D wxt
shnpm i -D wxt
shyarn add --dev wxt
添加入口点
my-project/entrypoints/background.ts
:tsexport default defineBackground(() => { console.log('Hello world!'); });
在
package.json
中添加脚本:json{ "scripts": { "dev": "wxt", "dev:firefox": "wxt -b firefox", "build": "wxt build", "build:firefox": "wxt build -b firefox", "zip": "wxt zip", "zip:firefox": "wxt zip -b firefox", "postinstall": "wxt prepare" } }
在开发模式下运行扩展
shpnpm dev
shbun run dev
shnpm run dev
shyarn dev
WXT 将自动打开已安装您扩展的浏览器窗口。