javascript - AMD modules with transitive dependencies -
suppose want create amd module depends on other amd module. doesn't matter what, tangible, suppose new kind of date-picker widget depends on moment.js
so setup bower.json looks this:
{ "name": "samplelib", "version": "0.0.1", "description": "test", "main": "mycontrol.js", "moduletype": [ "amd" ], "dependencies": { "moment": "~2.8.1" } }
ok, cool. no problem there.
my question how gets consumed... see 2 options, neither of love:
option one
concat code , moment.js unified script, , publish that. easy clients consume since have depend on module. in scenario:
- is moment.js devdependency, because clients don't have download it?
- if client depends on module also transitively depends on moment.js, there way around client loading library twice?
option two
don't concat code , keep moment.js declared dependency in bower.json. when client bower install
s library, they'll bring down moment.js. thats cool. thing worry namespacing... suppose depend on moment 'lib/moment', client structured depends on moment 'moment'? @ runtime, code fail because lib/moment isn't defined? worry brittle, there way harden this, besides documentation?
tl;dr
what robust way publish amd modules dependencies?
option 1 - while concatenating simpler distributing code, hit on 1 of issues doing - run risk of conflicts other libraries. increase size of js library.
option 2 - don't think you're referring namespacing here, rather path of module. correct? requirejs has config block can change base paths , mappings should solve issue you're referring to. http://requirejs.org/docs/1.0/docs/api.html#config
so, in case if want publish amd module , dependencies, still go option 2.
Comments
Post a Comment