Mozilla FireFox Addons -> Include external library in main.js

拥有回忆 提交于 2019-12-04 20:44:01

You would need to create a CommonJS module. Add your .js file inside the addon's lib folder and export all functions that you will be needing via the "exports" directive. Once you do that, you can use the exported functions via the "require" directive.

For example in the module that you will be reusing, you can put:

// REUSABLE MODULE
exports.somefunction = somefunction;

function somefunction() {
    doSomething();
 }

And then in the module that will be using this:

var othermodule = require("reusable_module");
othermodule.somefunction();

Here is the relevant documentation: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/guides/modules.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!