# vite-plugin-rails

> Convention over configuration for using Vite in Rails apps

Latest version **0.6.0** (published 2026-03-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-rails
pnpm add vite-plugin-rails
yarn add vite-plugin-rails
bun add vite-plugin-rails
```

## Health

**Score 65/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2026-03-17 |
| First published | 2022-10-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 6 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1591 |
| Author | Máximo Mussini |
| Maintainers | elmassimo |
| Keywords | plugin, rails, ruby, vite, vite-plugin, vitejs |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-rails
- Repository: https://github.com/ElMassimo/vite_ruby
- Homepage: https://github.com/ElMassimo/vite_ruby/blob/main/vite-plugin-rails
- Issues: https://github.com/ElMassimo/vite_ruby/issues
- npm.io page: https://npm.io/package/vite-plugin-rails

## Dependencies (6)

- [vite-plugin-ruby](https://npm.io/package/vite-plugin-ruby.md) ^5.0.0
- [rollup-plugin-gzip](https://npm.io/package/rollup-plugin-gzip.md) ^4.2.0
- [vite-plugin-environment](https://npm.io/package/vite-plugin-environment.md) ^1.1.3
- [vite-plugin-full-reload](https://npm.io/package/vite-plugin-full-reload.md) ^1.1.0
- [vite-plugin-manifest-sri](https://npm.io/package/vite-plugin-manifest-sri.md) ^0.2.0
- [vite-plugin-stimulus-hmr](https://npm.io/package/vite-plugin-stimulus-hmr.md) ^3.0.0

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2026-03-17
- 0.5.0 — 2023-11-16
- 0.1.0 — 2022-10-19

## README

<h2 align='center'><samp>vite-plugin-rails</samp></h2>

<p align='center'>Convention over configuration for Rails projects using Vite</p>

<p align='center'>
  <a href='https://www.npmjs.com/package/vite-plugin-rails'>
    <img src='https://img.shields.io/npm/v/vite-plugin-rails?color=222&style=flat-square'>
  </a>
  <a href='https://github.com/ElMassimo/vite_ruby/blob/master/LICENSE.txt'>
    <img src='https://img.shields.io/badge/license-MIT-blue.svg'>
  </a>
</p>

<br>

[vite_rails]: https://github.com/ElMassimo/vite_ruby/tree/main/vite_rails
[vite-plugin-ruby]: https://github.com/ElMassimo/vite_ruby/tree/main/vite-plugin-ruby
[configuration options]: https://github.com/ElMassimo/vite_ruby/tree/main/vite-plugin-rails/src/index.ts#L12-L84
[rollup-plugin-gzip]: https://github.com/kryops/rollup-plugin-gzip
[vite-plugin-environment]: https://github.com/ElMassimo/vite-plugin-environment
[vite-plugin-full-reload]: https://github.com/ElMassimo/vite-plugin-full-reload
[vite-plugin-stimulus-hmr]: https://github.com/ElMassimo/vite-plugin-stimulus-hmr
[vite-plugin-manifest-sri]: https://github.com/ElMassimo/vite-plugin-manifest-sri

## Installation 💿

In the future, [<kbd>vite_rails</kbd>][vite_rails] might install this plugin by default.

You can install it manually by running:

```bash
npm i vite-plugin-rails # yarn add vite-plugin-rails
```

## Usage 🚀

Add it to your plugins in `vite.config.ts`

```ts
// vite.config.ts
import Vue from '@vitejs/plugin-vue' // Example, could be using other plugins.
import ViteRails from 'vite-plugin-rails'

export default {
  plugins: [
    Vue(),
    ViteRails(),
  ],
};
```

## Batteries Included 🔋

Unlike [`vite-plugin-ruby`][vite-plugin-ruby], which provides the minimum amount of configuration necessary to get started, this plugin takes a Rails-approach of including plugins you would normally add.

You can configure each plugin by passing options, which are fully typed. See the [configuration options] for reference.

If you need finer-grained control, you can opt-out and use `vite-plugin-ruby` instead, manually adding only the plugins you need.

### [Ruby][vite-plugin-ruby]

[`vite-plugin-ruby`][vite-plugin-ruby] is added by default.

### Compression

This plugin uses [`rollup-plugin-gzip`][rollup-plugin-gzip] to create `gzip` and `brotli` compressed copies of your assets after build.

You can disable each manually:

```ts
    ViteRails({
      compress: { brotli: false }
    }),
```

```ts
    ViteRails({
      compress: false
    }),
```


### [Environment](https://github.com/ElMassimo/vite-plugin-environment)

[`vite-plugin-environment`][vite-plugin-environment] is used to expose environment variables to your
client code, using the [`import.meta.env`](https://vitejs.dev/guide/env-and-mode.html#env-files) convention from Vite.

This plugin allows you to conveniently provide defaults, or fail on required env variables:

```ts
    ViteRails({
      envVars: {
        API_KEY: null,
        OPTIONAL_KEY: '<opt-value>',
      },
    }),
```

### [Full Reload](https://github.com/ElMassimo/vite-plugin-full-reload)

[`vite-plugin-full-reload`][vite-plugin-full-reload] comes pre-configured to automatically reload the page
when making changes to server-rendered layouts and templates, improving the
feedback cycle.

You can override the default paths, or pass additional ones:

```ts
    ViteRails({
      fullReload: {
        additionalPaths: ['app/serializers/**/*']
      },
    }),
```

### [Stimulus HMR](https://github.com/ElMassimo/vite-plugin-stimulus-hmr)

[`vite-plugin-stimulus-hmr`][vite-plugin-stimulus-hmr] is included by default,
allowing you to see changes to your Stimulus controllers instantly without refreshing the page.

You can use the `stimulus` option if you need to configure it.

### [Subresource Integrity](https://github.com/ElMassimo/vite-plugin-manifest-sri)

[`vite-plugin-manifest-sri`][vite-plugin-manifest-sri] is included by default,
calculating a cryptographic hash for JavaScript and CSS assets, so that the browser
can verify the resources it fetches.

You can use the `sri` option if you need to configure it.

## License

This library is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/vite-plugin-rails · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
