vite-plugin-turbo-reload
v2.1.0
Published
Reload the page when files are modified via Hotwire Turbo
Maintainers
Readme
Why? 🤔
When using Vite Ruby, I wanted to see changes to server-rendered layouts and templates without having to manually reload the page.
vite-plugin-turbo-reload is a replacement for the vite-plugin-full-reload plugin, offering smoother and faster DOM updates when using Hotwire Turbo.
Installation 💿
Install the package as a development dependency:
npm i -D vite-plugin-turbo-reload # yarn add -D vite-plugin-turbo-reloadUsage 🚀
Add it to your plugins in vite.config.ts
import { defineConfig } from 'vite'
import TurboReload from 'vite-plugin-turbo-reload'
export default defineConfig({
plugins: [
TurboReload(['config/routes.rb', 'app/views/**/*', 'app/components/**/*'])
],
})This is useful to trigger a page refresh for files that are not being imported, such as server-rendered templates.
To see which file globbing options are available, check picomatch.
Limitation
- work only with Turbo version 8.0+
- if using plugin
vite-plugin-railsyou should setfullReload: false:
import { defineConfig } from 'vite'
import rails from "vite-plugin-rails"
import TurboReload from 'vite-plugin-turbo-reload'
export default defineConfig({
plugins: [
rails({ fullReload: false }),
TurboReload(['app/views/**/*', 'app/components/**/*']),
],
})Configuration ⚙️
The following options can be provided:
root
Files will be resolved against this directory.
Default:
process.cwd()TurboReload('config/routes.rb', { root: __dirname }),tailwindDirectivePath
Path to file, that contains Tailwind directive -
@tailwind baseor@import "tailwindcss"Default:
falseTurboReload('app/views/**/*', { tailwindDirectivePath: "app/frontend/stylesheets/tailwind.scss" })
License
This library is available as open source under the terms of the MIT License.
