Skip to content

Instantly share code, notes, and snippets.

@sinnbeck
Last active January 24, 2023 11:07
Show Gist options
  • Save sinnbeck/2b00a536921980bd3e781e1999b532ba to your computer and use it in GitHub Desktop.
Save sinnbeck/2b00a536921980bd3e781e1999b532ba to your computer and use it in GitHub Desktop.
Inertia hot reload
import {router} from '@inertiajs/react'
if (import.meta.hot) {
import.meta.hot.on('inertia:reload', () => {
router.reload()
})
}
function inertiaPlugin(paths) {
return {
name: 'inertia-refresh',
configureServer({ws, config}) {
const root = config.root
console.log(config.path)
const reload = (path) => {
ws.send('inertia:reload')
if (config.log ?? true) {
config.logger.info(
colors.green(`page reload `) + colors.dim(path),
{clear: true, timestamp: true}
)
}
}
chokidar
.watch(paths ?? 'app/**', {
cwd: root,
ignoreInitial: true,
...config,
})
.on('add', reload)
.on('change', reload)
},
}
}
//and use the plugin
plugins: [
laravel({input: ['resources/js/app.jsx', 'resources/css/app.pcss']}),
react(),
inertiaPlugin(['app/Actions/**']), //pass custom paths if needed. or just use the default 'app/**'
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment