gecko-dev/devtools/client/shared/vendor/REACT_UPGRADING

62 строки
2.5 KiB
Plaintext
Исходник Обычный вид История

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
We use a version of React that has a few minor tweaks. We want to use
an un-minified production version anyway, and because of all of this
you need to build React yourself to upgrade it for devtools.
First, clone the repo and get ready to build it. Replace `<version>`
with the version tag you are targetting:
* git clone https://github.com/facebook/react.git
* cd react
* git checkout <version>
* In `src/addons/ReactWithAddons.js`, move the
`React.addons.TestUtils = ...` line outside of the `if`
block to force it be include in the production build
Next, build React:
* npm install
* grunt build
Unfortunately, you need to manually patch the generated JS file. We
need to force React to always create HTML elements, and we do this by
changing all `document.createElement` calls to `createElementNS`. It's
much easier to do this on the generated file to make sure you update
all dependencies as well.
Open `build/react-with-addons.js` and search for all
`document.createElement` calls and replace them with
`document.createElementNS('http://www.w3.org/1999/xhtml', ...)`. Note
that some code is `ownerDocument.createElement` so don't do a blind
search/replace. There is only about ~14 places to change.
Now move into our repo (note the naming of `react-dev.js`, it's the dev version):
* cp build/react-with-addons.js <gecko-dev>/devtools/client/shared/vendor/react-dev.js
Now we need to generate a production version of React:
* NODE_ENV=production grunt build
Unfortunately, you need to manually replace all the `createElement`
calls in this version again. We know this is not ideal but WE NEED TO
MOVE OFF XUL and we don't need to do this anymore once that happens.
After patching `build/react-with-addons.js` again, copy the production
version over:
* cp build/react-with-addons.js <gecko-dev>/devtools/client/shared/vendor/react.js
You also need to copy the ReactDOM and ReactDOMServer package. It requires React, so
right now we are just manually changing the path from `react` to
`devtools/client/shared/vendor/react`.
* cp build/react-dom.js <gecko-dev>/devtools/client/shared/vendor/react-dom.js
* (change `require('react')` at the top of the file to the right path)
* cp build/react-dom.js <gecko-dev>/devtools/client/shared/vendor/react-dom-server.js
* (change `require('react')` at the top of the file to the right path)