requirejs-metagen
generate requirejs modules that represent dependencies in entire directories, useful for controllers, views, etc
how to use
We might have something like this on our front-end, most likely in a router module:
{ ; }
//so in order to require all those controllers, especially for use with r.js (the optimizer), we can do:
var grm = ; var controllerOpts = inputFolder: './public/static/app/js/controllers/all' appendThisToDependencies: 'app/js/controllers/' appendThisToReturnedItems: '' eliminateSharedFolder: true //will drop 'all' from the front of all return items output: './public/static/app/js/meta/allControllers.js' //puts all controllers in a directory its subdirectories into one RequireJS file/module ; ;
----> output looks like this module below:
//app/js/meta//allControllers.js ;
in your front-end program I recommend doing this:
requirejs;
then you can do:
;
or better yet, since those dependences are already loaded, you can use synchronous syntax easily
var allControllers = ;var carController = allControllers'more/cars';
usage with Gulp.js:
to use this library with Gulp, you can do it like so:
var metagens = "controllers": inputFolder: './public/static/app/js/controllers/all' appendThisToDependencies: 'app/js/controllers/' appendThisToReturnedItems: '' eliminateSharedFolder: true output: './public/static/app/js/meta/allControllers.js' "templates": inputFolder: './public/static/app/templates' appendThisToDependencies: 'text!app/' appendThisToReturnedItems: '' eliminateSharedFolder: false output: './public/static/app/js/meta/allTemplates.js' "css": inputFolder: './public/static/cssx' appendThisToDependencies: 'text!' appendThisToReturnedItems: '' eliminateSharedFolder: false output: './public/static/app/js/meta/allCSS.js' "flux-constants": inputFolder: './public/static/app/js/flux/constants' appendThisToDependencies: 'app/js/flux/' appendThisToReturnedItems: '' eliminateSharedFolder: false output: './public/static/app/js/meta/allFluxConstants.js' "flux-actions": inputFolder: './public/static/app/js/flux/actions' appendThisToDependencies: 'app/js/flux/' appendThisToReturnedItems: '' eliminateSharedFolder: false output: './public/static/app/js/meta/allFluxActions.js' "all-views": inputFolder: './public/static/app/js/jsx' appendThisToDependencies: 'app/js/' appendThisToReturnedItems: '' eliminateSharedFolder: true output: './public/static/app/js/meta/allViews.js' gulp;
any questions you can open an issue on Github or email me at alex@oresoftware.com, thanks