如何区分我正在建立的Firefox扩展开发和生产? [英] How to distinguish between dev and production in a Firefox extension I'm building?

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

问题描述

在我的Google Chrome浏览器扩展程序中,我使用这个漂亮的小技巧来区分开发版和生产版:



是否有类似的技巧可以用于Firefox扩展?在开发过程中,我想在代码中使用一些稍微不同的设置,但是在发布之前不必手动修改它们。

类似于:

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


解决方案

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

$ $ $ code 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已设置,我们在cfx下运行...);
}
else {
console.log(IS_DEV is not set?);



$ b $ p
$ b

查看文档获取更多信息:

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



使用在上面的用例中,你可以这样运行cfx:

$ p $ IS_DEV = 1 cfx run


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?

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.

Something like:

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

解决方案

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/en-US/developers/docs/sdk/1.7/packages/api-utils/environment.html

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

IS_DEV=1 cfx run

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

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