Live code editing with Browserify and React.
Hot reloading is de facto in today's front-end scene but unfortunately there isn't any decent implementation for Browserify yet. This is shame because (in my opinion) Browserify is the best bundling tool at the moment.
Hence the goal of this project is to bring the hot reloading functionality to Browserify by honoring its principles: simplicity and modularity.
LiveReactload can be used as a normal Browserify plugin. When applied to the bundle, it modifies the Browserify bundling pipeline so that the created bundle becomes "hot-reloadable".
And because one photo tells more than a thousand words, see the following video to see LiveReactload in action:
If you are a Webpack user, you probably want to check react-transform-boilerplate.
react >= 0.13.x in order to
Install pre-requirements (if not already exist)
npm i --save reactnpm i --save-dev watchify
babelify and its dependencies
npm i --save babelify babel-preset-es2015 babel-preset-react
Install React proxying components and LiveReactload
npm i --save-dev livereactload firstname.lastname@example.org babel-plugin-react-transform
.babelrc file into project's root directory (or add
if the file already exists). More information about
.babelrc format and options
can be found from babel-plugin-react-transform.
"presets": "es2015" "react""env":"development":"plugins":"react-transform""transforms":"transform": "livereactload/babel-transform""imports": "react"
And finally use LiveReactload as a Browserify plugin with
watchify. For example:
node_modules/.bin/watchify site.js -t babelify -p livereactload -o static/bundle.js
That's it! Now just start (live) coding! For more detailed example, please see the basic usage example.
Ideally your client code should be completely unaware of the reloading. However,
some libraries like
redux require a little hack for hot-reloading. That's why
By using this hook, you can add your own custom functionality that is executed in the browser only when the module reload occurs:
For more details, please see the redux example.
LiveReactload is build system agnostic. It means that you can use LiveReactload with all build systems having Browserify and Watchify support. Please see build systems example for more information.
Well... if you hide your state inside the modules then the reloading will lose the state. For example the following code will not work:
// counter.jsconst React =let totalClicks = 0
You can configure the LiveReactload Browserify plugin by passing some options
to it (
-p [ livereactload <options...> ], see Browserify docs for more information
about config format).
LiveReactload supports the following configuration options
Prevents reload server startup. If you are using LiveReactload plugin with Browserify (instead of watchify), you may want to enable this so that the process won't hang after bundling. This is not set by default.
Starts reload server to the given port and configures the bundle's client to
connect to the server using this port. Default value is
Configures the reload client to use the given hostname when connecting to the
reload server. You may need this if you are running the bundle in an another device.
Default value is
Disables Browserify module de-duplication. By default, de-duplication is enabled. However, sometimes this de-duplication with may cause an invalid bundle with LiveReactload. You can disable this de-duplication by using this flag.
Omits the reload client from the generated bundle.
Adds your custom SSL certificate and key to the reload web-server. This is needed if you want to use LiveReactLoad in HTTPS site. Parameters are paths to the actual files.
If you use a tool other than Babel to transform React syntax, this disables the in-browser warning that would otherwise appear.
Please create a Github issue if problems occur. Pull request are also welcome
and they can be created to the