reagent/docs/0.8-upgrade.md

79 lines
2.7 KiB
Markdown
Raw Normal View History

2017-07-31 10:36:34 +00:00
# 0.8 Upgrade guide
The necessary changes depend on what environment you target, and
how you want to provide React.
## Browser - Cljsjs
Using Reagent itself with Cljsjs packages doesn't require changes,
other than making sure you depend on the latest Cljsjs React packages,
if you have direct dependencies to them.
## Browser - node modules
You can use `:npm-deps` and `:install-deps` compiler options to
install the packages automatically.
If `react`, `react-dom` and `create-react-class` are available in `node_modules`
directory, ClojureScript compiler will use these with Reagent. **This
doesn't depend on use of `:npm-deps` option!** `:npm-deps` option is only about
installing the dependencies, if packages are available in `node_modules`
directory, they will be used.
2017-10-31 12:16:20 +00:00
You can use `:process-shim` compiler option to provide `process.env.NODE_ENV`
2017-07-31 10:36:34 +00:00
constant which is used by JS code to enable development and production
builds. ClojureScript compiler will automatically set this constant to
`production` value when using `:advanced` optimizations. This enables
the React production build.
2018-01-09 12:18:23 +00:00
## Browser - loading React from CDNJS or custom Webpack bundle
**TODO: Not tested properly**
If you want to load React.js yourself from external JS file (CDN) or from custom bundle,
it should be possible to override the Cljsjs foreign-libs, while still using externs from Cljsjs packages. To override the foreign-libs, you can provide following compiler option:
```clj
:foreign-libs
[{:file "empty.js",
:provides ["react" "react-dom" "create-react-class" "react-dom/server"],
:requires [],
2018-01-09 12:19:17 +00:00
:global-exports {react React
react-dom ReactDOM
create-react-class createReactClass
react-dom/server ReactDOMServer}}]
2018-01-09 12:18:23 +00:00
```
You'll also need to create the mentioned `empty.js` file (FIXME: relative to `project.clj`?).
If your bundle provides other libraries, you could extern `:provides` and `:global-exports` (e.g. `prop-types`).
## NodeJS - Cljsjs
Requires https://github.com/clojure/clojurescript/commit/f7d611d87f6ea8a605eae7c0339f30b79a840b49
Reagent should use Cljsjs libraries by default even when running on Node.
## NodeJS - node modules
2017-07-31 10:36:34 +00:00
Install `react`, `react-dom` and `create-react-class` npm packages,
and ClojureScript should automatically use `require` to
load React for Reagent.
## Electron
???
## React-native
https://github.com/drapanjanas/re-natal/issues/128
## Common Problems
### Mismatch with Cljsjs and npm packages
If you have one npm package installed, e.g. `react`, you also need
to provide others (`react-dom` and `create-react-class`), else
Cljsjs packages would be used for these, and packages from different sources
don't work together.