{"id":14955968,"url":"https://github.com/alignable/json_routes_webpack","last_synced_at":"2026-01-21T16:32:04.676Z","repository":{"id":56879587,"uuid":"109890302","full_name":"Alignable/json_routes_webpack","owner":"Alignable","description":"Export Rails named routes as json to be imported by webpack loaders","archived":false,"fork":false,"pushed_at":"2017-11-12T03:50:35.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-08T00:17:34.639Z","etag":null,"topics":["gem","json","rails","rails5","routes","webpack","webpacker"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alignable.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-07T21:00:40.000Z","updated_at":"2019-11-09T09:25:04.000Z","dependencies_parsed_at":"2022-08-20T11:40:43.774Z","dependency_job_id":null,"html_url":"https://github.com/Alignable/json_routes_webpack","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alignable%2Fjson_routes_webpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alignable%2Fjson_routes_webpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alignable%2Fjson_routes_webpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alignable%2Fjson_routes_webpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alignable","download_url":"https://codeload.github.com/Alignable/json_routes_webpack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247640472,"owners_count":20971558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","json","rails","rails5","routes","webpack","webpacker"],"created_at":"2024-09-24T13:12:06.075Z","updated_at":"2026-01-21T16:32:04.636Z","avatar_url":"https://github.com/Alignable.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version][gem]][gem-url]\n[![test][test]][test-url]\n[![coverage][cover]][cover-url]\n\n# JsonRoutesWebpack\n\nExports Rails named routes to JSON that can be loaded in Javascript via webpack loaders like [js-routes-loader](https://github.com/Alignable/js-routes-loader)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'json_routes_webpack'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install json_routes_webpack\n\n## Usage\n\n### Add a Rails initializer\n\nAdd an initializer that configures the routes you want to export and the file to write them too\n\n**config/initializers/json_routes_webpack.rb**\n```ruby\nJsonRoutesWebpack.configure do |config|\n  config.add_routes 'app/javascript/generated/routes.json'\nend\n```\n\nIn addition to the file name to write the routes `add_routes` supports two options arguments\n* `include` - an array of regular expressions the route name must match to be included\n* `exclude` - an array of regular expression tht the route name must not match\n\nExample: suppose you wanted to export you app and admin routes to separate files\n```ruby\nJsonRoutesWebpack.configure do |config|\n  config.add_routes 'app/javascript/routes/routes.json', exclude: [/admin/]\n  config.add_routes 'app/javascript/routes/admin_routes.json', include: [/admin/]\nend\n```\n\n### Configure Rake to build json routes before Webpacker compiles\n\nWe need the json routes to be available to webpack loaders add a rake hook to build the routes before Webpacker compiles our javascript\n\n**lib/tasks/js_routes.rake**\n```ruby\n# generate json routes before webpacker so they can be used by loaders\nif Rake::Task.task_defined?(\"webpacker:compile\")\n  Rake::Task[\"webpacker:compile\"].enhance [\"json_routes_webpack:compile\"]\nend\n```\n\n### Install `js-routes-loader` and configure Webpacker to use it for routes json files\n\n```bash\n$ yarn add js-routes-loader\n```\n\n**config/webpack/environment.js**\n```javascript\nconst { environment } = require('@rails/webpacker');\n\nenvironment.loaders.set('js-routes', {\n  test: /routes\\.json$/,\n  use: 'js-routes-loader',\n});\n\nmodule.exports = environment;\n```\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n[gem]: https://badge.fury.io/rb/json_routes_webpack.svg\n[gem-url]: https://badge.fury.io/rb/json_routes_webpack\n\n[test]: http://img.shields.io/travis/Alignable/json_routes_webpack.svg\n[test-url]: https://travis-ci.org/Alignable/json_routes_webpack\n\n[cover]: https://codecov.io/gh/Alignable/json_routes_webpack/branch/master/graph/badge.svg\n[cover-url]: https://codecov.io/gh/Alignable/json_routes_webpack\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falignable%2Fjson_routes_webpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falignable%2Fjson_routes_webpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falignable%2Fjson_routes_webpack/lists"}