-
Notifications
You must be signed in to change notification settings - Fork 79
Multiple includes with relative require()s #120
Comments
It could be great feature! |
FYI this is on the top of my list when I get to doing new stuff, the more I think about it the more I want to have this for my own work, completely replace existing build steps and let you develop browser code just like you would for Node. |
See ender-js/ender-js#13 and #126 |
That would be so awesome. Actually.. what is the current way of including multiple files? |
If you're asking about a standard module, then in in 0.8.x the |
I had assumed that ender includes the files referenced in |
Should be fixed in the 1.0-wip branch @enyo. Install with |
Thanks a lot! That did it... |
That's fine. We're using this as a forum for support at the moment, nothing else has stuck so feel free to open issues or comment in others if you have questions. Or bug someone on twitter. |
Maybe we could make the adjustments of package.json fields optional, if we're using detective to find all local requires? |
@niclashoyer I've thought a bit about this and my current opinion is that I'd like to avoid magic as much as possible. I'd rather have package authors be explicit about which files are included. Perhaps I could be persuaded by the weight of others' opinions though so will try to keep an open mind going forward. |
I have implemented a rough version of this feature. The current implementation is probably fairly brittle, but it required very little modification to the existing codebase. It needs more work (and testing!) before it can really be considered merge-able. I ended up calling the key There are issues if you also allow arrays in the Of course, this wouldn't be an issue if you just treated the Any comments either here or inline on the commit would be welcome. |
Nice, I've had a quick look and it looks like a great start, I'd be keen to have a play with it. I did imagine that we could cut down the overhead of the duplicated internal look-up stuff by implementing it in the client lib ('ender-js', make global |
I went ahead and moved the require mechanics to the client lib. That allows the passed-in require function in the package templates to be pretty minimal: function (path) { return require(path, "{{mainPath}}", "{{packageName}}:"); } Right after I wrote my last comment, realized why I didn't just go with the solution of converting the I think the next step would be writing some tests, but I'm still wrapping my head around the testing code. In case it helps anyone, here's a gist for a basic package I created for testing. |
I wish it would've been stated somewhere on the site that Ender doesn't follow require() statements... It really didn't feel good to have to find this out after an hour of trying to figure out why the rest of my files don't make into the final build file. Is it correct to assume that Ender expects to work with just one JS file per module? That doesn't seem like a realistic scenario to me. |
This is now supported in |
Just recording this while I think of it.
Since people seem to assume that Ender supports
require('./relative')
and can bundle multiple files into a single build, why not support it?Some package.json adjustments would be required. maybe:
or
If you have multiple includes then it wraps the whole lot with a version of
require()
that can resolve local names but those names aren't available outside of the bundle. e.g. dist/module1.js could callrequire('./module2.js')
but you couldn't do the same from another ender package. It could even be made aware of the relative locations of the files so you canrequire('../lib/file.js')
from one location andrequire('./file.js')
from the same directory as file.js and resolve to the same module depending on what module it was called from -- making it pretty much the same as what people expect from Node.The text was updated successfully, but these errors were encountered: