如何在Firefox扩展I& m构建中区分开发人员和生产人员? [英] How to distinguish between dev and production in a Firefox extension I'm building?

查看:51
本文介绍了如何在Firefox扩展I& m构建中区分开发人员和生产人员?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Google Chrome扩展程序中,我使用了这个漂亮的小技巧来将开发版本与生产版本区分开:

In my Google Chrome extension, I'm using this nifty little trick to distinguish the dev version from the production version: How to tell if a Chrome extension is installed by a real user vs. by me during development?

我可以将类似的技巧用于Firefox扩展吗?我想在开发时在代码中使用一些稍有不同的设置,但不必在发布前手动更改它们.

Is there a similar trick I can use for a Firefox extension? I'd like to use some slightly different settings in my code while developing, but without having to manually change them before releasing.

类似的东西:

if (addon_in_development) {
    setting = 'abc';
}
else {
    setting = 'def';
}

推荐答案

您可以在shell中设置一个环境变量,然后像这样检测它:

You could set an environment variable in the shell, and detect it like this:

var { env } = require('api-utils/environment');

console.log(env.IS_DEV);
console.log(typeof env.IS_DEV);

if (env.IS_DEV) {
    console.log("IS_DEV is set, we're running under cfx run...");
}
else {
    console.log("IS_DEV is not set?");
}

有关更多信息,请参阅文档:

See the docs for more info:

https://addons.mozilla.org/zh-CN/developers/docs/sdk/1.7/packages/api-utils/environment.html

使用上述用例,您将像这样运行cfx:

Using the above use case, you would run cfx like this:

IS_DEV=1 cfx run

这篇关于如何在Firefox扩展I& m构建中区分开发人员和生产人员?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆