{"id":13879431,"url":"https://github.com/joelmoss/frails","last_synced_at":"2025-07-16T15:32:22.207Z","repository":{"id":34476914,"uuid":"179359467","full_name":"joelmoss/frails","owner":"joelmoss","description":"Frails == Front End on Rails","archived":true,"fork":false,"pushed_at":"2022-07-22T03:03:43.000Z","size":24287,"stargazers_count":3,"open_issues_count":20,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-16T02:39:33.182Z","etag":null,"topics":["css","frontend","javascript","rails","webpack"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joelmoss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-03T19:48:55.000Z","updated_at":"2023-01-27T22:38:54.000Z","dependencies_parsed_at":"2022-07-29T08:29:15.146Z","dependency_job_id":null,"html_url":"https://github.com/joelmoss/frails","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joelmoss%2Ffrails","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joelmoss%2Ffrails/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joelmoss%2Ffrails/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joelmoss%2Ffrails/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joelmoss","download_url":"https://codeload.github.com/joelmoss/frails/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226143895,"owners_count":17580245,"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":["css","frontend","javascript","rails","webpack"],"created_at":"2024-08-06T08:02:20.931Z","updated_at":"2024-11-24T08:31:21.167Z","avatar_url":"https://github.com/joelmoss.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Frails == Modern Front End on Rails\n\nFrails is a modern asset pipeline for [Rails](https://rubyonrails.org), built on [Webpack](https://webpack.js.org/). Its aims are:\n\n- Follow convention over configuration as much as possible.\n- Tight integration with Rails, without tying you up in knots.\n- Un-opinionated webpack configuration - batteries not included!\n- Full Webpack control without fighting with the likes of Webpacker.\n- Embrace modern front end practices.\n\nPLUS...\n\n- Side loaded layouts, views and partials.\n- Components\n  - React + SSR\n  - Ruby/HTML\n\n## Installation\n\nFrails is designed to work only within a Rails application, so must be installed in an existing Rails app. It also requires Node.js, Yarn and a valid `package.json` file in your app root.\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'frails'\n```\n\nAnd then execute:\n\n    $ bundle\n\nThen run the installer:\n\n    $ bin/rails frails:install\n\n## Usage\n\nFrails tries to keep as close as possible to a standard Webpack setup, so you can run webpack and webpack-dev-server in the usual way. For example, using yarn you can build:\n\n    $ yarn webpack\n\nor run the dev server:\n\n    $ yarn webpack-dev-server\n\nRails will proxy requests to any running Webpack dev server.\n\n### Using in Tests\n\nPlease note that Frails is not designed or intended to be run in your test environment. This would require a full webpack compile on every test run, which would slow your tests down hugely! Instead, I recommend that you test your Javascript independently using the likes of Jest or some other good Javascript test runner.\n\n### Webpack Configuration\n\nFrails requires the user of the `webpack-assets-manifest` webpack plugin in order for its helpers to\nwork correctly. This is because it needs to be able lookup the real paths of assets, and the\nmanifest file provides that data.\n\n```javascript\nmodule.exports = {\n  ...\n  plugins: [\n    new WebpackAssetsManifest({\n      writeToDisk: true,\n      entrypoints: true,\n      publicPath: true\n    })\n  ]\n}\n```\n\n### Rails Helpers\n\n#### `javascript_pack_tag`\n\nJust like `javascript_include_tag`, but will use your webpack assets.\n\n```ruby\njavascript_include_tag 'application'\n```\n\n#### `stylesheet_pack_tag`\n\nJust like `stylesheet_link_tag`, but will use your webpack assets.\n\n```ruby\nstylesheet_pack_tag 'application'\n```\n\n#### `image_pack_tag`\n\nJust like `image_tag`, but will use your webpack assets.\n\n```ruby\nimage_pack_tag 'logo.png'\n```\n\n### Side Loaded Assets\n\nFrails has the ability to automatically include your Javascript and CSS based on the current layout\nand/or view. It even supports side loading partials.\n\nJust set the `side_load_assets` class variable to your `ApplicationController`, or indeed to any\ncontroller.\n\n```ruby\nclass ApplicationController \u003c ActionController::Base\n  self.side_load_assets = true\nend\n```\n\nAs an example, given a view at `/app/views/pages/home.html.erb`, we can create\n`/app/views/pages/home.css` and/or `/app/views/pages/home.js`. These side-loaded assets will then be\nincluded automatically in the page.\n\n```yml\napp/views/pages: ├── home.html.erb\n  ├── home.css\n  ├── home.js\n  ├── _header.html.erb\n  ├── _header.css\n```\n\nMake sure you yield the side loaded CSS and JS tags; `\u003c%= yield :side_loaded_css %\u003e` in your\n`\u003chead\u003e`, and `\u003c%= yield :side_loaded_js %\u003e` at the bottom of the body:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eMy App\u003c/title\u003e\n    \u003c%= yield :side_loaded_css %\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003c%= yield %\u003e \u003c%= yield :side_loaded_js %\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nCSS is included in-line for faster renders, and JS is included as `\u003cscript src=\"...\"\u003e` tags. Check\nout `./package/side_load.js` for the webpack config needed to make this work.\n\n#### Partials and CSS Modules\n\nPartial CSS supports CSS Modules, and it is recommended that partial CSS are compiled as local CSS\nmodules. Then in your partial, you can use the `css_module` attribute on any HTML tag, and it will\nbe replaced with the compiled class name of the CSS module.\n\nSo given a partial `views/layouts/_awesome.html.erb`:\n\n```html\n\u003cdiv css_module=\"base\"\u003eHello World\u003c/div\u003e\n```\n\nand a stylesheet at `views/layouts/_awesome.css`:\n\n```css\n.base {\n  color: red;\n}\n```\n\nWhen the partial is rendered, it will look something like this:\n\n```html\n\u003cdiv class=\"app-views-layouts-_awesome__base___abc123\"\u003eHello World\u003c/div\u003e\n```\n\nAnd the compiled CSS:\n\n```css\n.app-views-layouts-_awesome__base___abc123 {\n  color: red;\n}\n```\n\nOf course in theory, you could apply this to all your side loaded CSS, but Frails will only\ntransform `css_module` HTML attributes in partials.\n\nYour Webpack config could use the following to compile your partial CSS as modules (local), and\nlayout and view CSS normally (global):\n\n```javascript\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        // Partials - modules (local)\n        test: /app\\/views\\/.+(\\/_([\\w-_]+)\\.css)$/,\n        use: [\"style-loader\", \"css-loader\"],\n      },\n      {\n        // Layouts and views - no CSS modules (global)\n        test: /app\\/views\\/.+(\\/[^_]([\\w-_]+)\\.css)$/,\n        use: [\"style-loader\", \"css-loader\"],\n      },\n    ],\n  },\n};\n```\n\n## Configuration\n\nFrails is built to be as simple as possible, so has very few configuration options:\n\n- `Frails.dev_server_host` - The HTTP port that Rails will proxy asset requests to. (default: `8080`)\n- `Frails.dev_server_path` - The HTTP host that Rails will proxy asset requests to. (default: `localhost`)\n- `Frails.public_output_path` - The public path where Webpack will output its build to, relative to your app's `/public` directory. (default: `assets`)\n- `Frails.manifest_path` - Path to the produced Webpack manifest file, relative to the `public_output_path`. (default: `manifest.json`)\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` 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/joelmoss/frails.\n\n## Thanks\n\nA huge thank you goes out to the peeps behind [Webpacker](https://github.com/rails/webpacker). Frails has borrowed heavily from Webpacker, particularly for the dev server proxy and minifest code. 🙏\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoelmoss%2Ffrails","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoelmoss%2Ffrails","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoelmoss%2Ffrails/lists"}