I'm working on porting a Chrome extension over to Firefox. In the Chrome extension, the background script includes JQuery, which is used for AJAX throughout the background scripts.
With the Firefox Jetpack SDK, it looks like i can do:
require("modulename")
but this only works if modulename is a firefox extension module, including the code:
exports.someVar = someLocalVar
in order to make the module functionality available elsewhere. Obviously JQuery isn't set up as a module like this, so there's no way to require it.
Is there some way to include JQuery in my lib/main.js file in the background of my Firefox addon, such that I get access to JQuery in my main() function?
Since posting this, I've recognized that it's a somewhat futile endeavor. As Wladimir Palant points out in the comments, JQuery is meant to access the DOM. Since the main.js file has no window or document objects, this functionality is entirely useless.
I had intended to use JQuery for AJAX, which works correctly in Chrome backgrounds scripts, but Firefox addons have no XMLHttpRequest object, so JQuery is pretty useless here as well. The correct solution is to rewrite my code using the firefox Request() API instead.
If you would like to include JQuery in CommonJS applications, I found this project, which puts JQuery into a module, assuming you have window, document, and XMLHttpRequest defined: https://github.com/jakobmattsson/commonjs-jquery