Skip to content

Commit

Permalink
fix: root hot for parcel bundler, fixes #1082
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Mar 29, 2019
1 parent dd3e5d9 commit a16679b
Show file tree
Hide file tree
Showing 5 changed files with 3,187 additions and 611 deletions.
30 changes: 12 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,12 @@ npm install react-hot-loader
## 🔥 HOT-LABS 🔥

Latest (4.5.0+, beta) version of React-Hot-Loader could be quite 🔥!
Latest (4.5.0+) version of React-Hot-Loader could be quite 🔥!

> RHL will patch React, replace React-DOM by React-🔥-DOM and work with fiber directly
* (required) [use webpack plugin](https://github.com/gaearon/react-hot-loader#webpack-plugin) to let RHL patch React-DOM for you.
* (alternative) [use react-🔥-dom](https://github.com/gaearon/react-hot-loader#react--dom) to use already patched React-DOM.
* (optional) [set configuration](https://github.com/gaearon/react-hot-loader#setconfigconfig) to `ignoreSFC:true` (this will fix `hook`)
* (optional) [set configuration](https://github.com/gaearon/react-hot-loader#setconfigconfig) to `pureRender:true` (this will remove side effect from Classes)

```js
import { setConfig } from 'react-hot-loader'

setConfig({
ignoreSFC: true, // RHL will be __completely__ disabled for SFC
pureRender: true, // RHL will not change render method
})
```

## Getting started

Expand All @@ -66,23 +55,28 @@ const App = () => <div>Hello World!</div>
export default hot(App)
```

3. [Run webpack with Hot Module Replacement](https://webpack.js.org/guides/hot-module-replacement/#enabling-hmr):

```sh
webpack-dev-server --hot
```

### Old API

**Note:** There is also an old version of `hot`, used prior to version 4.5.4. **Please use the new one**,
as it is much more resilient to js errors that you may make during development.

Meanwhile, not all the bundlers are compatible with new `/root` API, for example **[parcel](http://parceljs.org/) is not**.

React-Hot-Load will throw an error, asking you to use the old API, if such incompatibility would be detected.
It is almost the same, but you have to pass `module` inside `hot`.

```js
import { hot } from 'react-hot-loader'
const App = () => <div>Hello World!</div>
export default hot(module)(App)
```

3. [Run webpack with Hot Module Replacement](https://webpack.js.org/guides/hot-module-replacement/#enabling-hmr):

```sh
webpack-dev-server --hot
```

## Limitations

* (that's the goal) React-Hot-Loader would not change the past, only update the present - no lifecycle event would be called on component update.
Expand Down
9 changes: 5 additions & 4 deletions examples/parcel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
"start": "parcel index.html"
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"parcel-bundler": "^1.4.1"
"parcel-bundler": "^1.12.3"
},
"dependencies": {
"react": "^16.2.0",
"react-dom": "^16.2.0",
"react-hot-loader": "next"
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-hot-loader": "^4.8.0"
}
}
4 changes: 2 additions & 2 deletions examples/parcel/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { hot } from 'react-hot-loader'
import { hot } from 'react-hot-loader/root'
import Counter from './Counter'

const App = () => (
Expand All @@ -9,4 +9,4 @@ const App = () => (
</h1>
)

export default hot(module)(App)
export default hot(App)

0 comments on commit a16679b

Please sign in to comment.