mercredi 15 avril 2015

Gulp generate index.js of all files in folder

I'm working on a nodejs project using gulp and browserify.


I want to include a folder of modules of which I don't know the filenames in my main js file.


My initial thoughts on how to approach this are:




  1. run a gulp script to create an index.js file for all the files in the folder




  2. require the generated index.js file in the main browserify file




  3. run browserify




Example:


dir structrure:



/
/models
/model1.js
/model2.js


desired ouput object:



{
"model1": {...},
"model2": {...}
}


where {...} is the object exported by the file using module.exports.


Is this the right approach? Are there any better ways to approach this?


And if this is the right approach, I'm not sure how to achieve it using gulp (creating an index file), so any pointers would be greatly appreciated.


Thanks,


Rik


Aucun commentaire:

Enregistrer un commentaire