-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
feat: hmr error recovery #435
base: master
Are you sure you want to change the base?
Changes from 4 commits
17acb10
607532d
ad42401
ed9f295
380f822
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = function loader() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any other suggestion then for a moniker to use to indicate tests that are expected to fail?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rjgotten just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adjusted the test pattern in |
||
const callback = this.async(); | ||
callback(new Error('I am error')); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["check"],{ | ||
|
||
/***/ "./index.css": | ||
/***/ (function(module, exports, __webpack_require__) { | ||
|
||
// extracted by mini-css-extract-plugin | ||
if(true) { | ||
// 1479427200000 | ||
var cssReload = __webpack_require__("../../../src/hmr/hotModuleReplacement.js")(module.i, {"hmr":true,"locals":false}); | ||
module.hot.dispose(cssReload); | ||
module.hot.accept(function(){}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A little more context please: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we need this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. Will add a small description in the loader.js where this particular line of code is emitted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
module.hot.accept(undefined, cssReload); | ||
} | ||
|
||
throw new Error("ModuleBuildError: Module build failed (from ./error-loader.js):\nError: I am error\n at Object.loader (error-loader.js:1:1)"); | ||
|
||
/***/ }) | ||
|
||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.a { | ||
background: red; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { HotModuleReplacementPlugin } from 'webpack'; | ||
|
||
import Self from '../../../src'; | ||
|
||
module.exports = { | ||
entry: './index.css', | ||
mode: 'development', | ||
devtool: false, | ||
output: { | ||
filename: '[name].js', | ||
}, | ||
optimization: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why it is necessary for test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. output.filename is a leftover. I'll remove it. The optimization settings are there to force everything but the compiled module itself into a separate chunk (which is then also not emitted). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the filename leftover, and left a comment explaining why the optimization chunk settings are being used. |
||
runtimeChunk: 'single', | ||
namedModules: true, | ||
namedChunks: true, | ||
splitChunks: { | ||
chunks: 'all', | ||
cacheGroups: { | ||
vendors: { | ||
test: /[\\/]index\.css$/, | ||
name: 'check', | ||
enforce: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
{ | ||
loader: Self.loader, | ||
options: { | ||
hmr: true, | ||
}, | ||
}, | ||
require.resolve('./error-loader'), | ||
], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new HotModuleReplacementPlugin(), | ||
new Self({ | ||
filename: '[name].css', | ||
}), | ||
{ | ||
apply(compiler) { | ||
compiler.hooks.emit.tapAsync('no-emit', (compilation, callback) => { | ||
const { assets } = compilation; | ||
|
||
// Not interested in comparing output for these. | ||
delete assets['runtime.js']; | ||
delete assets['main.js']; | ||
|
||
callback(); | ||
}); | ||
}, | ||
}, | ||
], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For catching errors, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It was moved down passed the dependencies, to ensure those dependenices are always tracked.
Flipping the error state into a success state on the parent compilation, means that it will also update its registered dependencies. (If the parent compilation would fail, it would retain the previous set.)
If we'd drop out of the child compilation because of an error before the dependencies of the child compilation are moved into the parent, then we would 'lose' those dependencies, including any change watches on them. This way, we won't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be a case where multiple errors need to be shown in the errors array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ScriptedAlchemy
Not sure actually. The current version of the plugin only reports the first child compilation error as well.