railsware / js-routes

Brings Rails named routes to javascript

Home Page:http://railsware.github.io/js-routes/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable tree shaking

hibachrach opened this issue · comments

First of all, thank you so much for this lovely package!

As one's config/routes.rb file grows, the resulting output of js-routes grows in turn. Since all the route functions are effectively static, it would be nice if there was another output format that enabled users of js-routes to take advantage of tree shaking from bundle managers like Webpack.

If you're open to PRs, I'd be interested in writing one that achieves this.

Here's some info on how to achieve that in Webpack.

I doubt that this can solve a problem better than exclude and include option + a strict maintanance of routes.rb to remove routes that don't have related controller actions (I think someone should have already done a gem that cleans this up).

However, I am open to change my opinion and will gladly review a PR and its pros and cons.

Thank you for the reply and for your time! I'm approaching js-routes from the perspective of a primarily traditional Rails application where the majority of routes are not being used by the JS bundle.

So the unfortunate thing about exclude and include is that it requires you to know at all times which routes are being used by your front-end JS bundle. With tree shaking, all routes that are not imported are removed automatically.

If I were to work on a PR, would it be acceptable to do this per-route exporting be based on a configuration option?

If I were to work on a PR, would it be acceptable to do this per-route exporting be based on a configuration option?

That sounds reasonable, I am open for such a change. I hope it will not yield a ton of changes in internals.

That sounds reasonable, I am open for such a change. I hope it will not yield a ton of changes in internals.

Happy to hear that! I will see what happens. If it feels like it would require altering significant portions of the package, I might consider forking.

This seems like it would be highly beneficial, especially for webpacker setups.

Try version 2.0. Feel free to followup on problems here or open another issue.