I am building a Firefox add-on and like to include code that is used in the index.js, as well as in the worker script. Instead of copying the function, I would like to add it in a file next to the index.js if possible.
Asked
Active
Viewed 74 times
3
-
The question, of course, is: how does that work? – Dandorid Jan 10 '16 at 11:21
-
[This](http://docs.nodejitsu.com/articles/getting-started/what-is-require) article hinted me to export my function, which finally gave me access to it. However, when used in my worker, it complained that my 'exports' variable was not defined... Can I use the same file in my worker and my central code? – Dandorid Jan 16 '16 at 11:35
1 Answers
3
for addon modules you use require("./relative/path.js"), for the worker you specify it through the contentScriptFile parameter. You will have to feature-detect whether CommonJS features (require/exports) are available.

the8472
- 40,999
- 5
- 70
- 122