-
-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support fs.readdir and fs.readdirSync #19
Comments
There is now a pull request to enable this; see #21. |
I don't really understand the use-case for this feature since browserify can only read |
Dependencies wouldn't be parsed, but by passing the required source files manually into browserify, it should work; no? |
Here's a use-case : For example we have a
Each listener module have a bind function. So with one line I want to require all listener modules and call the bind function on each. /**
* Use require() or I don't know something like requireFolder()
*/
var listeners = require('./Listeners');
listeners.forEach(function(listener){
listeners.bind();
}); So before browerify the var listeners = [
require('./Listeners/KeyListener.js'),
require('./Listeners/MouseListener.js'),
...
]; or var listeners = {
KeyListener: require('./Listeners/KeyListener.js'),
MouseListener: require('./Listeners/MouseListener.js'),
...
}; I need something like this in my project. |
I'd like to have a file that require()s all files in a directory, then make a bundle with browserify. I think this would be useful, or basically supporting |
it would be cool if there was some way this could work: var fs = require('fs');
var templates = {};
fs.readdirSync(__dirname + '/../templates').forEach(function (filename) {
templates[filename] = fs.readFileSync(__dirname + '/../templates/' + filename, 'utf-8');
}); |
Did someone find a solution/workaround for this issue? |
@callumlocke I don't think you can use both readdir and readFile in the same snippet since brfs it won't be able to statically evaluate it. you always need to maintain the list of files manually in the code, IMO the best you can do is maintaiining the array of files in the code:
If you really need to do serialize files automatically you can use tools like https://github.com/cancerberoSgx/fs-to-json - will serialize a glob in a json file that you can require() or import . As brfs this is a build-time tool. Perhaps would be interesting to implement a browserify transformation with which you can perform |
@callumlocke finally made it and working fine! https://github.com/cancerberoSgx/br-fs-to-json packing a glob of files is what I always wanted and since you will be requiring a "strange" library fs-to-json I make sure it doesn't contaminate your project with its dependencies. Much more practical than brfs IMO |
I think this is feasible, and I personally think this is really useful.
In node.js it's reasonably common for me to do things like:
This allows us to abstract whole parts of the code, later on - even treat them as completely separate modules:
If we could do this with browserify, things like bootstrapping an Ember app, could be automated. I know there are a couple of problems.
Here's an analogous example that works, though not exactly as one would hope it'd.
I know this has to do with limitations on the browserify module (which may be impossible to address) but this would be really cool.
Perhaps we could even parse things like:
Into:
Or provide an utility
requireMap
thing that resolved into that.I don't know if this is a relevant issue. But I though this would be a nice thing, if it was possible.
At it's core, the main point was simply to add:
To be transformed into:
What do you think?
The text was updated successfully, but these errors were encountered: