Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: Make hot reload work on files containing only import statements
If a file only has import statements, the parser would crash when hot
module reloading was enabled because firstNonImportDeclarationNode would
be undefined. This makes those files work by adding the hot module block
at the end of the file in those cases.
  • Loading branch information
trygveaa committed Apr 19, 2017
commit a605e437c90beb7f3186c57457ca9a8552e73cda
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ export default ({

const hotAcceptStatement = t.ifStatement(test, consequent);

firstNonImportDeclarationNode.insertBefore(hotAcceptStatement);
if (firstNonImportDeclarationNode) {
firstNonImportDeclarationNode.insertBefore(hotAcceptStatement);
} else {
programPath.pushContainer('body', hotAcceptStatement);
}
};

const getTargetResourcePath = (path: Object, stats:Object) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './bar.css';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.a {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import './bar.css';

if (module.hot) {
module.hot.accept('./bar.css', function () {
require('./bar.css');
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"plugins": [
[
"../../../../src",
{
"generateScopedName": "[name]__[local]",
"webpackHotModuleReloading": true
}
]
]
}