-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to hot reloading clear console ? #565
Comments
You could hack into hot reload messages like this: window.addEventListener('message', function onWebpackMessage (e) {
// do something
}); |
Awesome ! It's perfectly work ! |
Add this to your apps // Clear after module reload
window.addEventListener('message', e => {
if ('production' !== process.env.NODE_ENV) {
console.clear();
}
}); For example, this is part of my index.jsx entry point: ...
const render = Component => {
ReactDOM.render(
<Provider store={store}>
<MuiThemeProvider className='full-size'>
<Component />
</MuiThemeProvider>
</Provider>,
document.getElementById('root')
);
};
render(App);
if (module.hot) {
module.hot.accept();
window.addEventListener('message', e => {
if ('production' !== process.env.NODE_ENV) {
console.clear();
}
});
}
|
This doesn't work right for me--it clears the console on any message. How can I get it to clear only on an HMR reload? |
@szalapski I'm using vue-cli and don't know if it changes something on the messages sent by the webpack-dev-server, but in my case this works: window.addEventListener('message', e => {
if (process.env.NODE_ENV !== 'production' && e.data && e.data.type === 'webpackInvalid') {
console.clear();
}
}); So the console will be cleared as soon as webpack detects the change (at least that's what I think |
I don't appear to ever have "e.data". I have e.payload and e.source, and nothing in them seems to distinguish a HMR-reload event from any other. |
@szalapski Which version of the dev server are you running? Mine is the latest, |
How do I find that? I don't see a "devServer" anywhere in my .js files. It's a basic web server, right? It appears I am not using it. Instead, I use HTTP.sys (since this is an ASP.NET Core site) with Webpack dev middleware. But, I'm not sure why the web server is related to this--maybe it is in the way the server communicates HMR events? Maybe this is the wrong place to ask, but it is the only place on the web that seems to address it at all. I'll go ask on stackoverflow. |
This seemed to work better for me.
See also https://stackoverflow.com/a/53933757/7453 . |
When the code is hot reload, is there a chrome/firefox plugin or anything to show the seperation from the reload in the console ?
Or add something like
console.log("--------------------------------------");
to separate them ?The text was updated successfully, but these errors were encountered: