I'm building a cordova plugin and want to split my JS layer on N files:
- www/myPlugin.js
- www/myPlugin/utils.js
- www/myPlugin/core.js
In www/myPlugin.js I want to export the functionality exported by utils.js and core.js:
module.exports = {
utils: require('./myPlugin/utils'),
core: require('./myPlugin/core')
}
This is so easy when working in Node, but I don't know whether this would work in Cordova given that I have to declare a <js-module> for each JS file, and once those files are loaded in the app (by means of a XHR) they cannot "find" to each other. From the doc:
At load time, code in cordova.js uses XHR to read each file and inject a tag into HTML
Can I just add in plugin.xml a <js-module> for each JS file? If so, would require('./myPlugin/core.js') just work when Cordova reads it in "www/myPlugin.js"?
Or should I rather create a bundled JS file with browserify and place it into www/ with a single <js-module>?
The question is: if I add two JS files (a.js and b.js) how could I require('./b') from a.js once both files are handled by Cordova? Should I use cordova.require()? I don't want that each JS file exports stuff to window namespace.
Thanks a lot.