On 2015-12-18 9:31 AM, Yuri Astrakhan wrote:
Trevor and Daniel, thanks for your reply.
How would you structure the code that is to be shared? Should it be a
separate NPM package, referenced from the extension package.json via git
url, and have a small file in the extension's lib/ dir with a oneliner -
"require('...')" that browserify could pick up? And have a script
command
in package.json to build that file?
Both options are valid.
You can use browserify to make a standalone browser build of a library
and use it via ResourceLoader.
This will allow it to be shared. But it raises the possibility that
there some type of conflict may happen in the global space.
You can use browserify to make a script that'll expose a global
require('...') with the module(s). Same pros and caveats as standalone
builds. Though a mild reduction in the conflicts that could happen.
Or you could write your code in CommonJS/node-like style and browserify
that without declaring any of the dependencies as external. Then all the
things you need will be bundled with your code. You'll eliminate all
possible conflicts. But modules will definitely be duplicated since
nothing is shared.
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [
http://danielfriesen.name/]