odysseyscience / react-router-proxy-loader

Dynamically load react-router components on-demand, based on react-proxy-loader
145 stars 12 forks source link

Infer name from filename #19

Closed Anahkiasen closed 8 years ago

Anahkiasen commented 8 years ago

This loader is very nice but it's a bit cumbersome to have to specify the name of the chunk every time to not have a bunch of numbered chunks. Would it be possible to make the loader use the file name by default as name? Like if I do require('react-router-proxy!../Routes/Rooms') it would be equivalent to require('react-router-proxy?name=rooms!../Routes/Rooms')?

Anahkiasen commented 8 years ago

Alternatively the ability to use Webpack placeholders in the name attribute would be sufficient, personally, like react-router-proxy?name=[name]. That way I could simply set up the loader globally in my webpack.config.js for all JS files in a specific folder.

seanadkinson commented 8 years ago

This would be nice for not having numbered bundles, but it could theoretically conflict with other named bundles that have been explicitly defined elsewhere.

For example, if I have an entry point bundle I've named bundle.app.js, and then I require('react-router-proxy?./App'), it would produce the same bundle name, which would be bad.

I'll leave this open as an Enhancement for now, and we'll see if there is something that can be done cleanly.

Anahkiasen commented 8 years ago

You could prefix the chunks with something, which is already what I do. Like name=routes/[name] which would generate all bundles into a subfolder, thus avoiding conflicts

seanadkinson commented 8 years ago

Oh, that's cool. Didn't realize the bundles could have a slash in the name and create a sub directory. I don't really have time atm to look into this, but the code is pretty basic (really just one file), so if you wanted to take a stab at it, I could check out your PR. Obviously need to consider existing user behavior, and possibly make this an opt-in feature somehow.

Anahkiasen commented 8 years ago

Will take a look. It would definitely be opt-in since you'd have to manually use the placeholders for it to kick in, so it shouldn't break anything, at least not without the user being aware of what changed.