如何在Firefox扩展I& m构建中区分开发人员和生产人员? [英] How to distinguish between dev and production in a Firefox extension I'm building?
问题描述
在我的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屋!