Open AndreasCag opened 6 years ago
Hrm, i thought there was a way to customise the process-update behaviour and the arguments passed to module.hot.apply
, but it doesn't look like that was ever introduced.
The code was last touched in https://github.com/webpack-contrib/webpack-hot-middleware/pull/254 The arguments we pass to the hot reloading API look to be the same as what webpack core uses: https://github.com/webpack/webpack/blob/master/hot/only-dev-server.js#L25-L55
Is there a way to configure CSS loader to not error in that scenario?
There is my small mistake, error is emitted by style-loader
https://github.com/webpack-contrib/style-loader/blob/fc24512b395a8a3fd4074d88cd3f7b195f0bcef2/index.js#L59
Suddenly there is no way to customize style-loader
hmr behavior.
Right now I implement console.error wrapper to handle this error
const consoleErrorMethod = console.error;
console.error = (...args: any[]) => {
if (
typeof args[0] === 'object'
&& args[0]
.toString()
.startsWith('Error: Aborting CSS HMR due to changed css-modules locals')
) {
window.location.reload();
}
consoleErrorMethod.apply(console, args);
};
By I feel a bit uncomfortable with this solution.
Note: webpack-dev-server
refresh page when I add new css rule
@glenjamin To solve this problem the following options should be customizable?
ignoreUnaccepted: true,
ignoreDeclined: true,
ignoreErrored: true,
I believe I can make a PR on this weekend for this capabilities.
I think it might be a bit more complicated than that to get the behaviour correct.
I think perhaps the right logic might be to not ignore if reload is true.
Description
I use
css-loader
with enabledmodules
option. When I add any new css rulecss-loader
throw error:In that case I want to reload page, but
webpack-hot-widdleware
ignores any errors and I'm not able to handle errors and reload page.Reproduction
https://github.com/AndreasCag/hot-reload-bug-repro
How Do We Reproduce?
npm i
npm run dev
localhost:3000
./src/test.css
and add the following rule at the end of fileActual behaviour
Expected behaviour
Page automatically reloaded