joeybaker / remapify

Alias directories for browserify
Other
117 stars 23 forks source link

Resolve index.js when no file is provided. #41

Closed ehynds closed 8 years ago

ehynds commented 8 years ago

Fixes #20

joeybaker commented 8 years ago

Thanks @ehynds!

joeybaker commented 8 years ago

If you can make that one change @ehynds, I'll merge this. Thank you!

ehynds commented 8 years ago

all set, @joeybaker

joeybaker commented 8 years ago

Thanks @ehynds

joeybaker commented 8 years ago

Released as 2.1.0

roncli commented 8 years ago

Fair warning to rendr users. When you expose ./app/views/default/index.js to both app/view/default AND app/view/default/index in two separate b.require() calls, browserify seems to only acknowledge the first require call it gets for a particular file. It is unclear if this is a bug in browserify, or if it is intended behavior.

This breaks functionality for rendr. I can work around this when handling the remapify:files event. If the expanded alias does not contain index.js OR the key contains index, I pass it into b.require(). Combining this logic with my logic for ensuring that it only requires the file when it does not contain .js and when there are no backslashes in the key, this is my final event handler:

b.on("remapify:files", function(file, expandedAliases) {
    Object.keys(expandedAliases).forEach(function(key) {
        if (key.indexOf(".js") === -1 && key.indexOf("\\") === -1 && (expandedAliases[key].indexOf("index.js") === -1 || key.indexOf("index") !== -1)) {
            b.require(path.resolve(expandedAliases[key]), {expose: key});
        }
    });
});

Obviously, this is messy. I'd rather not have to do this. If anyone knows a way around this, I'm open to suggestions.