Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(*): setup hot reload for react / with babel6
Using the following: * babel-plugin-react-transform - https://github.com/gaearon/babel-plugin-react-transform * react-transform-hmr - https://github.com/gaearon/react-transform-hmr Most of the work is in the .babelrc Note: Any task running babel loaders (most likely builds, dev server, tests) will run with HMR on if NODE_ENV is not set or set to 'development', so if you have the following error, you may have to pass NODE_ENV=production NODE_ENV=mock (according to the use case): Error: locals[0] does not appear to be a `module` object with Hot Module replacement API enabled. You should disable react-transform-hmr in production by using `env` section in Babel configuration. See the example in README: https://github.com/gaearon/react-transform-hmr
- Loading branch information
Showing
3 changed files
with
26 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,20 @@ | ||
{ | ||
"presets": ["es2015", "react"], | ||
"plugins": ["transform-class-properties", "transform-es2015-destructuring", "transform-object-rest-spread", "add-module-exports"] | ||
"plugins": ["transform-class-properties", "transform-es2015-destructuring", "transform-object-rest-spread", "add-module-exports"], | ||
"env": { | ||
// only enable it when process.env.NODE_ENV is 'development' or undefined | ||
"development": { | ||
"plugins": [["react-transform", { | ||
"transforms": [{ | ||
"transform": "react-transform-hmr", | ||
// if you use React Native, pass "react-native" instead: | ||
"imports": ["react"], | ||
// this is important for Webpack HMR: | ||
"locals": ["module"] | ||
}] | ||
// note: you can put more transforms into array | ||
// this is just one of them! | ||
}]] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters