{"id":18621681,"url":"https://github.com/jdlehman/rails_external_assets","last_synced_at":"2025-08-18T20:35:26.130Z","repository":{"id":56890541,"uuid":"59171508","full_name":"jdlehman/rails_external_assets","owner":"jdlehman","description":"Use external assets, frontend assets built with another build tool outside of the asset pipleline, in Rails.","archived":false,"fork":false,"pushed_at":"2018-11-16T16:46:16.000Z","size":50,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-28T11:58:56.488Z","etag":null,"topics":["asset-pipeline","frontend-assets","sprockets","webpack"],"latest_commit_sha":null,"homepage":null,"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/jdlehman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-19T03:41:39.000Z","updated_at":"2019-03-06T19:50:13.000Z","dependencies_parsed_at":"2022-08-21T00:20:32.049Z","dependency_job_id":null,"html_url":"https://github.com/jdlehman/rails_external_assets","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/jdlehman/rails_external_assets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdlehman%2Frails_external_assets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdlehman%2Frails_external_assets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdlehman%2Frails_external_assets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdlehman%2Frails_external_assets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdlehman","download_url":"https://codeload.github.com/jdlehman/rails_external_assets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdlehman%2Frails_external_assets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271056702,"owners_count":24691808,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["asset-pipeline","frontend-assets","sprockets","webpack"],"created_at":"2024-11-07T04:13:06.277Z","updated_at":"2025-08-18T20:35:26.086Z","avatar_url":"https://github.com/jdlehman.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/rails_external_assets.png)](http://badge.fury.io/rb/rails_external_assets)\n[![Build Status](https://secure.travis-ci.org/jdlehman/rails_external_assets.svg?branch=master)](http://travis-ci.org/jdlehman/rails_external_assets)\n\n# RailsExternalAssets\n\nRailsExternalAssets allows you to use the frontend build tool of your choice ([webpack](https://webpack.github.io/), [jspm](http://jspm.io/), [browserify](http://browserify.org/), etc) with Rails. Essentially you can build all (or some) of your frontend assets outside of Rails' asset pipeline, but still make use of them in Rails. The only requirement is that you provide an asset manifest file, which is a json file that maps your asset files to their final built files:\n\n```json\n{\n  \"js/module.js\": \"builds/js/module-12312abc.js\",\n  \"js/react-component.jsx\": \"builds/components/react-component-ab123x.js\",\n  \"css/styling.sass\": \"builds/styles/styling-129xha.css\",\n  \"pathToPreBuiltAsset\": \"pathToBuiltAsset\"\n}\n```\n\nThis means you can manage your frontend assets however you like and RailsExternalAssets gives you [Rails](http://rubyonrails.org/) view helpers and [Sprockets](https://github.com/rails/sprockets) directives to incorporate these external assets into your Rails application. In Rails environments, RailsExternalAssets also hooks into `assets:precompile` and `assets:clobber` Rake tasks.\n\nYou can use RailsExternalAssets without using Ruby on Rails, but you will have to wire up the helper methods it provides into your application yourself.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rails_external_assets'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install rails_external_assets\n\n## Usage\n\n## With Rails\n\nYou can include your external assets in Rails with the provided view helpers or Sprockets directives.\n\nRailsExternalAssets will also hook into the `assets:precompile` Rake command and run the shell script defined by the `build_script` config. It will also hook into the `assets:clobber` Rake command and remove all the files in the directory specified by your `base_path` config (where your assets are built).\n\n### View Helpers\n\n#### JavaScript\n\nYou can include a JavaScript file with `external_asset_js`. Note that the string argument must correspond to an entry in the manifest file, including the file extension. If you do not include a file extension, `js` will be used by default.\n\n```erb\n\u003c%= external_asset_js 'myFile.js' %\u003e\n```\n\n#### CSS\n\nYou can include a CSS file with `external_asset_css`. Note that the string argument must correspond to an entry in the manifest file, including the file extension. If you do not include a file extension, `css` will be used by default.\n\n```erb\n\u003c%= external_asset_css 'myFile.css' %\u003e\n```\n\n#### Image\n\nYou can include a Image file with `external_asset_img`. Note that the string argument must correspond to an entry in the manifest file, including the file extension.\n\n```erb\n\u003c%= external_asset_img 'myFile.jpg' %\u003e\n```\n\n### Sprockets Directives\n\nBy default, you can use the `external_require` directive in JavaScript and CSS manifest files, but you can add more (Sass, SCSS, CoffeeScript, etc) by setting the configuration (check out the configuration docks for `sprockets_directives`).\n\nIn any file type you configure the Sprockets directive to be available in you, can use the `external_require` directives to include an external asset in the Sprockets manifest. If you do not include an extension, Sprockets will try to use an extension based on the extension of the file you required it in. Sprockets will also ensure that each file is only included once, even if directives overlap and require the file more than once.\n\nThe available directives are, `external_require`, `external_require_directory`, and `external_require_tree`, corresponding to the build in directives, `require`, `require_directory`, and `require_tree`.\n\nAn example `application.js` Sprockets manifest file:\n\n```js\n//= require normalAsset\n//= require more/anotherAsset\n//= external_require externals/firstAsset\n//= external_require externals/anotherAsset\n//= external_require_directory externals/myFolder\n//= external_require_tree externals/folderWithMoreFolders\n```\n\nThis will include the first two JS assets, `normalAsset` and `anotherAsset` from Rails' asset pipeline, and the other JS assets, `firstAsset`, `anotherAsset`, all JS files directly in `externals/myFolder`, and all JS files in the tree `externals/folderWithMoreFolders` from your external assets. The external assets are resolved by looking up these files in the asset manifest JSON file provided.\n\n## With Plain Ruby\n\nThe `RailsExternalAssets::AssetFinder` class provides three class methods for your disposal.\n\n`asset_path` takes a path to an external asset file, and returns the corresponding built asset path by looking up the key in the asset manifest JSON file.\n\n`exeternal_asset` takes a path and returns the built asset path (the result of `asset_path`) and joins it with the base path. If a block is provided, the external asset path is passed to the block and the resulting value is returned.\n\n`asset_manifest` is used by `asset_path`, and returns the asset manifest file parsed as JSON.\n\n## Configuration\n\nConfiguration settings can be modified within the `RailsExternalAssets.configure` block. Or set directly off of `RailsExternalAssets.config`\n\n```ruby\nRailsExternalAssets.configure do |config|\n  config.base_path = '/assets/'\n  config.manifest_file = 'public/assets/asset-manifest.json'\nend\n\nRailsExternalAssets.config.base_path = '/webpack-assets/'\n```\n\n### Options\n\n**base_path**\n\nThis is the file location off of Rails' `public/` folder that the external assets are built to.\n\n\u003e Defaults to `/external-assets/`\n\n**manifest_file**\n\nThis is the file location of the asset manifest JSON file. The keys are the file paths pre-build, and the values are the file paths post-build.\n\n\u003e Defaults to `public/external-assets/manifest.json`\n\n**sprockets_directives**\n\nThis is an array to configure the use of the `external_assets` Sprockets directive that is provided by RailsExternalAssets. Each item is a hash with keys for `mime_type` and the `comments` supported by the directive. Check out the [Sprockets documentation](https://github.com/rails/sprockets/blob/master/guides/extending_sprockets.md#adding-directives-to-your-extension) for more information.\n\n\u003e Defaults to:\n```ruby\n[\n  { mime_type: 'application/javascript', comments: ['//', ['/*', '*/']] },\n  { mime_type: 'text/css', comments: ['//', ['/*', '*/']] }\n]\n```\n\n**build_script**\n\nThis is the shell script that will be run prior to `assets:precompile` in Rails or with the `rake assets:build_external_assets` command. This should be the script that builds your assets (eg: `npm run build`).\n\nNote that in a Rails environment, `assets:clobber` will also remove all the files in your `base_path` directory (where your assets are built).\n\n\u003e Defaults to `echo \"You did not define a build script\"`\n\n**cache_manifest**\n\nThis is specifies whether the manifest should be cached. This should probably be false for development and true in production.\n\n\u003e Defaults to `true`\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/jdlehman/rails_external_assets. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdlehman%2Frails_external_assets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdlehman%2Frails_external_assets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdlehman%2Frails_external_assets/lists"}