Last active
January 24, 2023 11:07
-
-
Save sinnbeck/2b00a536921980bd3e781e1999b532ba to your computer and use it in GitHub Desktop.
Inertia hot reload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {router} from '@inertiajs/react' | |
if (import.meta.hot) { | |
import.meta.hot.on('inertia:reload', () => { | |
router.reload() | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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