{"id":15020191,"url":"https://github.com/elmassimo/vite-plugin-erb","last_synced_at":"2025-08-03T11:33:24.962Z","repository":{"id":45388346,"uuid":"364951511","full_name":"ElMassimo/vite-plugin-erb","owner":"ElMassimo","description":"Use ERB files in Vite.js projects with a Ruby backend","archived":false,"fork":false,"pushed_at":"2022-07-14T13:47:26.000Z","size":286,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-05T15:49:58.655Z","etag":null,"topics":["erb","rails","ruby","vite-plugin","vitejs"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/ElMassimo.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-06T15:12:04.000Z","updated_at":"2024-09-10T17:18:33.000Z","dependencies_parsed_at":"2022-07-13T21:44:51.282Z","dependency_job_id":null,"html_url":"https://github.com/ElMassimo/vite-plugin-erb","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fvite-plugin-erb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fvite-plugin-erb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fvite-plugin-erb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElMassimo%2Fvite-plugin-erb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElMassimo","download_url":"https://codeload.github.com/ElMassimo/vite-plugin-erb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228542282,"owners_count":17934262,"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":["erb","rails","ruby","vite-plugin","vitejs"],"created_at":"2024-09-24T19:54:42.585Z","updated_at":"2024-12-07T00:27:48.732Z","avatar_url":"https://github.com/ElMassimo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch2 align='center'\u003e\u003csamp\u003evite-plugin-erb\u003c/samp\u003e\u003c/h2\u003e\n\n\u003cp align='center'\u003eUse ERB files in \u003csamp\u003eVite.js\u003c/samp\u003e projects with a Ruby backend\u003c/p\u003e\n\n\u003cp align='center'\u003e\n  \u003ca href='https://www.npmjs.com/package/vite-plugin-erb'\u003e\n    \u003cimg src='https://img.shields.io/npm/v/vite-plugin-erb?color=222\u0026style=flat-square'\u003e\n  \u003c/a\u003e\n  \u003ca href='https://github.com/ElMassimo/vite-plugin-erb/blob/main/LICENSE.txt'\u003e\n    \u003cimg src='https://img.shields.io/badge/license-MIT-blue.svg'\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n[plugin]: https://github.com/ElMassimo/vite-plugin-erb\n[migration]: https://vite-ruby.netlify.app/guide/migration.html#migrating-to-vite\n[vite.js]: http://vitejs.dev/\n[rails-erb-loader]: https://github.com/usabilityhub/rails-erb-loader\n[define]: https://vitejs.dev/config/#define\n[Vite Ruby]: https://vite-ruby.netlify.app/config/#source-maps-%F0%9F%97%BA\n[sprockets]: https://github.com/rails/sprockets\n[jsfromroutes]: https://github.com/ElMassimo/js_from_routes\n[spring]: https://github.com/rails/spring\n\n## Disclaimer ⚠️\n\nThis library is intended for __legacy projects__—please do not use it on new projects.\n\nUsing ERB with JS and CSS files can lead to a fragile setup where your frontend assets\nare entangled with your backend setup, making it very hard to migrate to\ndifferent tooling or frameworks.\n\nThe goal of this library is to ease out the transition as you __gradually remove__ your `.js.erb` files.\n\nIf you need to share constants or values between the backend and the frontend,\na safer and more performant approach is to instead [generate JS or TypeScript from Ruby][jsfromroutes]\nand import it as usual (or viceversa).\n\n## Why? 🤔\n\nWhen migrating to [Vite.js] from [sprockets] or similar asset pipelines, it's\nnot unusual to have `.erb` files that depend on the Ruby runtime to be rendered.\n\nThis plugin allows Vite.js to understand `.erb` files, and render them in the\ncontext of your Ruby application.\n\nIt provides the same functionality as \u003ckbd\u003e[rails-erb-loader]\u003c/kbd\u003e, but for Vite.js.\n\n## Installation 💿\n\nInstall the package as a development dependency:\n\n```bash\nnpm i -D vite-plugin-erb # yarn add -D vite-plugin-erb\n```\n\nand then add the plugin to your `vite.config.ts` file:\n\n```js\nimport { defineConfig } from 'vite'\nimport Erb from 'vite-plugin-erb'\n\nexport default defineConfig({\n  plugins: [\n    Erb(),\n  ],\n})\n```\n\n## Usage 🚀\n\nOnce the plugin is installed, you should be able to start importing `.erb` files.\n\n```js\n// app/frontend/constants.js.erb\n\nexport const railsEnv = \u003c%= Rails.env.to_json %\u003e\n```\n\n```js\nimport { railsEnv } from '~/constants.js.erb'\n\nconsole.log(`Running in ${railsEnv}`)\n```\n\n## Configuration ⚙️\n\nIf things are not working out of the box, you might need to tweak some the\nfollowing settings.\n\nFor example:\n\n```js\nplugins: [\n  Erb({\n    engine: 'erb',\n    runner: 'ruby ./boot.rb',\n    env: { RACK_ENV: process.env.NODE_ENV },\n    extendEnv: false,\n    timeout: 5000,\n  }),\n],\n```\n\n### `engine`\n\nThe ERB template engine to use. `erubi`, `erubis` and `erb` are supported.\n\nYou can manually specify which one to use if needed, but they will be detected automatically.\n\n### `runner`\n\nThe command to run the internal ruby script.\n\nIf `bin/rails` is detected, Rails runner will be used, giving you access to the\napplication environment.\n\nYou may provide `ruby ./boot.rb` or something similar if using other frameworks.\n\n### `env`\n\nAdditional environment variables to be passed to runner. Defaults to `process.env`.\n\n### `extendEnv`\n\nSet to false if you want to override `process.env` instead when providing the \u003ckbd\u003eenv\u003c/kbd\u003e property.\n\n### `timeout`\n\nTe Ruby process will be sent a termination signal if it doesn't return a result\nunder the specified timeout in millis. Defaults to `10000`.\n\n## A note about [spring] 🌺\n\nBy default `DISABLE_SPRING: '1'` is set in \u003ckbd\u003eenv\u003c/kbd\u003e because if the\n[spring] client is started from Node.js the Ruby renderer process would never finish.\n\nThis makes the rendering process significantly slower, specially in large apps.\n\nYou may provide `env: { DISABLE_SPRING: '0' }` to re-enable [spring], but make\nsure to run `bin/rails runner ''` before starting the Vite dev server to prevent\nthis issue, or reload the page after the first visit (which would timeout).\n\n## Acknowledgements\n\n- [rails-erb-loader]: Provided the foundation for this library. Thanks!\n\n## License\n\nThis library is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmassimo%2Fvite-plugin-erb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felmassimo%2Fvite-plugin-erb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmassimo%2Fvite-plugin-erb/lists"}