Closed gabrielecirulli closed 10 years ago
Node does not know the concept of mass-inclusion, because it does not make sense there. In contrast to ruby, where required modules modify the global namespace, node modules are executed in a local context and export things explicitly. And these exports are the return value of the require call. What should a mass require return? And if it does not return anything, it is not useful, because requiring is side effect free.
You should rethink your code organization and read up on the node.js module system. If you cannot restructure your code, the node way and in corollary browserify is not right for you.
PS: Of course there are ways, to do all the bad stuff, but I am not going to help you with that.
This is more of a question than an issue. I am looking for a proper way to require all of the JS files present in a directory.
Here are the approaches I tried:
require("./directory/*")
. Fails with the following:index.js
file in the target directory, and then using ERB where I extract the file names in the directory to generate JS code that requires all of the files. This seems to fail because browserify looks forindex.js
and sprockets does not seem to automatically generate the file by evaluatingindex.js.erb
.What's the correct way to do this?