Last active
September 29, 2020 17:20
-
-
Save benperiton/4adf9769140043dfc7d2132cc90b6c33 to your computer and use it in GitHub Desktop.
Getting HMR working with Lando and Laravel
This file contains 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
proxy: | |
node: | |
- hmr.my-app.lndo.site:8080 | |
services: | |
node: | |
type: node:12.16 | |
ssl: true | |
scanner: false | |
build: | |
- yarn | |
command: yarn hot |
This file contains 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
// Where the HMR stuff is served from - the node proxy in lando | |
const hmrLocation = 'hmr.my-app.lndo.site'; | |
// Set the config properly for HMR and lando | |
const landoHMRConfig = { | |
devServer: { | |
host: '0.0.0.0', | |
port: 8080, // The same port as in the lando proxy | |
public: hmrLocation, // So the response contains the correct URL | |
}, | |
// Only because https is only set by passing --https to dev server, which breaks lando service | |
output: { | |
publicPath: Mix.isUsing('hmr') | |
? `https://${hmrLocation}/` | |
: '/' | |
} | |
}; | |
// Replace the default 'hot' file with one with the correct URL in | |
// https://github.com/JeffreyWay/laravel-mix/blob/3be45d55c5f7448b85ae8038ad69541fbc36b299/src/index.js#L52 | |
Mix.listen('init', () => { | |
if (Mix.shouldHotReload()) { | |
new File(path.join(Config.publicPath, 'hot')).write(`https://${hmrLocation}/`) | |
} | |
}); | |
mix | |
.js('resources/js/app.js', 'public/js') | |
.webpackConfig(landoHMRConfig); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment