HMR and React with Mix
See original GitHub issue- Laravel Mix Version: 1.4.5 (
npm list --depth=0
) - Node Version (
node -v
): 7.3.0 - NPM Version (
npm -v
): 3.10.10 - OS: Windows 10
Description:
Hi, I’m trying to run Hot reloading for my react assets for a long time but without any success. I was trying many configurations from GH and nothing works. Could you help / share your config and tell what exactly should I do for enable it.
My webpack.mix.js:
mix.webpackConfig({
devtool: "source-map", devServer: {
contentBase: path.resolve(__dirname, 'public'),
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['react-hot-loader/webpack', 'babel'],
}]
},
entry: {
'app': [
'babel-polyfill',
'react-hot-loader/patch',
'./resources/assets/js/app'
]
}
});
mix.react('resources/assets/js/app.js', 'public/js').sourceMaps(true);
mix.sass('resources/assets/sass/app.scss', 'public/css').sourceMaps(true);
.babelrc:
{
"plugins": ["transform-decorators-legacy", "transform-class-properties", "transform-object-rest-spread", "react-hot-loader/babel"]
}
my app.js:
import 'react-hot-loader/patch';
import React from 'react'
import ReactDOM from 'react-dom'
import {AppContainer} from 'react-hot-loader';
import App from './components/App'
import './styles/app.scss'
const MOUNT_NODE = document.getElementById('app');
ReactDOM.render(
<AppContainer>
<App/>
</AppContainer>
,
MOUNT_NODE
);
if (process.env.NODE_ENV === 'development' && module.hot) {
module.hot.accept();
}
And hot script in package.json:
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --output-public-path=public/ --config=node_modules/laravel-mix/setup/webpack.config.js",
Generally hot script starts without errors, and it says that compiled successfully, I am on app.dev and js file is loaded from localhost:8080, but there are no any effect in browser, also there are nothing about HMR in console. Watching files with browserSync works well but it reloads full page, but I want to achieve hot reload.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:8
Top Results From Across the Web
HMR and React with Mix · Issue #1222
Hi, I'm trying to run Hot reloading for my react assets for a long time but without any success. I was trying many...
Read more >Laravel Mix Hot Module Reloading With React
Laravel Mix Hot Module Reloading With React. Interested in a boilerplate with HMR included amongst React Router, Typescript support and more ...
Read more >Hot Module Replacement | Laravel Mix Documentation
Hot Module Replacement (or Hot Reloading) allows you to, not just refresh the page when a piece of JavaScript is changed, but it...
Read more >Using Webpack's Hot Module Replacement with React
Out of the box, webpack supports a fancy new alternative to live reload to see if your changes worked called hot module replacement,...
Read more >Setting Up Webpack for React and Hot Module Replacement
Now that we have a basic webpack configuration set up we can add React to the mix. Let's install React and write a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Do you have any solutions for this issue ?
In my laravel project it working now Package use:
and my mix config
App.tsx
Hope it helps.