建模方式
因为 WXT 是基于 Vite 的,它支持与 Vite 相同的 模式。
在运行任何开发或构建命令时,请通过 --mode 选项指定模式:
bash
wxt --mode production
wxt build --mode development
wxt zip --mode testing默认情况下,--mode 为 development 对于 wxt 命令,而对于其他命令(如 build、zip 等)则为 production。
获取运行时模式
您可以通过 import.meta.env.MODE 访问您的扩展中的当前模式:
typescript
switch (import.meta.env.MODE) {
case 'development': // ...
case 'production': // ...
// 使用 --mode 指定的自定义模式
case 'testing': // ...
case 'staging': // ...
// ...
}