{"id":22801,"library":"vite-plugin-rails","title":"Vite Rails Plugin","description":"vite-plugin-rails v0.6.0 is a Vite plugin that brings convention over configuration to Rails projects, bundling several commonly needed plugins (Ruby integration, gzip/brotli compression, environment variable exposure, full reload on template changes, Stimulus HMR, and SRI manifest hashing) with zero-config defaults while remaining fully configurable. Unlike the minimal vite-plugin-ruby, this plugin provides an opinionated, batteries-included setup for Rails developers. Released under MIT license, maintained by ElMassimo as part of the vite_ruby ecosystem. Requires Vite >=5.0.0.","status":"active","version":"0.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/ElMassimo/vite_ruby","tags":["javascript","plugin","rails","ruby","vite","vite-plugin","vitejs","typescript"],"install":[{"cmd":"npm install vite-plugin-rails","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-rails","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-rails","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required plugin peer dependency for Vite build tool.","package":"vite","optional":false}],"imports":[{"note":"Default import; the plugin ships TypeScript types. ESM only; CJS require will cause error at runtime.","wrong":"const ViteRails = require('vite-plugin-rails')","symbol":"ViteRails","correct":"import ViteRails from 'vite-plugin-rails'"},{"note":"The package exports a `ViteRailsOptions` interface for configuring the plugin in TypeScript.","symbol":"type ViteRailsOptions","correct":"import type { ViteRailsOptions } from 'vite-plugin-rails'"},{"note":"The package has a default export; named export `ViteRailsPlugin` does not exist. Use default import.","wrong":"import { ViteRailsPlugin } from 'vite-plugin-rails'","symbol":"default","correct":"import ViteRailsPlugin from 'vite-plugin-rails'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport ViteRails from 'vite-plugin-rails';\n\nexport default defineConfig({\n  plugins: [\n    ViteRails({\n      compress: { gzip: true, brotli: false },\n      envVars: { RAILS_ENV: process.env.RAILS_ENV ?? 'development' },\n      fullReload: { additionalPaths: ['app/serializers/**/*'] },\n      stimulus: { controllersPath: 'app/assets/controllers' }\n    })\n  ]\n});","lang":"typescript","description":"Registers the plugin with Vite config, showing optional compression, environment variables, full reload paths, and Stimulus HMR configuration."},"warnings":[{"fix":"Replace import from 'vite-plugin-ruby' to 'vite-plugin-rails'; adjust options to match the new config shape.","message":"Upgrading from vite-plugin-ruby (without the -rails suffix) requires switching to the new package name and updated API.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Update Vite to version 5.0.0 or higher.","message":"vite-plugin-rails v0.6.0 requires Vite >=5.0.0; older Vite versions are incompatible.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Refer to the latest src/index.ts for valid options.","message":"The plugin may deprecate or remove old option keys; always check the latest configuration options source.","severity":"deprecated","affected_versions":">=0.5.0"},{"fix":"Use plugin options to configure bundled plugins; pass `compress: false` to disable completely.","message":"External plugins like rollup-plugin-gzip and vite-plugin-full-reload are bundled by default; do not install them separately or duplicate them in plugins array.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Set `fullReload: { additionalPaths: [] }` or configure to match your exact template patterns.","message":"The default fullReload paths may trigger unnecessary full page reloads on certain file changes if custom caching is used.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `npm install vite-plugin-rails --save-dev` (or yarn) and ensure package.json includes it.","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'vite-plugin-rails' or its corresponding type declarations."},{"fix":"Upgrade Vite to version 5.0.0 or newer.","cause":"Installed Vite version is too old.","error":"Error: [vite] Internal server error: The plugin 'vite-plugin-rails' requires Vite version >=5.0.0. Current version: 4.x"},{"fix":"Ensure options object is properly formatted; for example, set `compress: { gzip: true, brotli: false }`.","cause":"Passed invalid options object (e.g., undefined or malformed).","error":"TypeError: Cannot read properties of undefined (reading 'gzip')"},{"fix":"Ensure build is run with the plugin; check if `vite build` completes and manifest.json is produced.","cause":"SRI plugin expects manifest to be generated by Vite build but it's missing.","error":"UnhandledPromiseRejectionWarning: Error: No manifest.json found."},{"fix":"Switch to `import ViteRails from 'vite-plugin-rails'` and ensure your project uses ESM (type: module in package.json).","cause":"Using CommonJS require() instead of ESM import.","error":"Dynamic require of 'vite-plugin-rails' is not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}