javascript - Is it possible to set dependencies for a folder using require.js? -


is possible set dependencies entire folder using require.js?

i know can use shim configuration set dependencies file:

require.config({     shim: {         'plugin/backbone/xyz': {             deps: ['lib/backbone'],             exports: 'backbone'         }     } }); 

in above example define dependencies plugin backbone/xyz, define dependencies backbone plugins:

require.config({     shim: {         'plugin/backbone/': { // specify folder here doesn't work.             deps: ['lib/backbone'],             exports: 'backbone'         }     } }); 

i think once found gist on github, can't seem find again.


to clarify: isn't requiring entire folder, setting dependencies - files in folder needs before ready initialize, each , 1 of them. accomplished adding shims files, have add shim once entire folder:

shim: {     'lib/backbone': {         exports: 'backbone' // <- no use of .noconflict() plugins can required , export backbone well.     },     'plugin/backbone/a': {         deps: ['lib/backbone'], // <- require backbone         exports: 'backbone' // <- export backbone     },     // same requirement , folder these files:     'plugin/backbone/b': {         deps: ['lib/backbone'],         exports: 'backbone'     },     'plugin/backbone/c': {         deps: ['lib/backbone'],         exports: 'backbone'     } } 

no, cannot create wildcard add dependencies files under folder configuration itself. can create loop before config , add whichever dependencies want.

var config = {     shim: {         'plugin/backbone/xyz': {             deps: ['lib/dependency'],             exports: 'backbone'         }     } }; for(var shim in config.shim) {     if(shim.indexof('plugin/backbone/') == 0) {         if(config.shim[shim].deps == null) {             config.shim[shim].deps = [];         }         config.shim[shim].deps.push('lib/backbone');     } } require.config(config); 

this way can think of without having override 1 of require's functions yourself. not elegant, admit, job.


Comments