- React Components
- Christopher Pitt
- 242字
- 2021-07-09 19:34:44
Debugging in the browser
We can also use our code directly in the browser. There may be times when we want to see the effects of a change, without a build step. In such cases, we can try something like this:
$ npm install --save babel-core $ npm install --save systemjs
These will give us access to a browser-based dependency manager and cross-compiler; that is, we can use unbundled source code in an example HTML file:
<!DOCTYPE html> <html> <head> <script src="/node_modules/babel-core/browser.js"></script> <script src="/node_modules/systemjs/dist/system.js"></script> </head> <body> <p class="react"></p> <script> System.config({ "transpiler": "babel", "map": { "react": "/examples/react/react", "react-dom": "/examples/react/react-dom", "page": "/src/page" }, "defaultJSExtensions": true }); System.import("main"); </script> </body> </html>
This uses the same unprocessed main.js
file as before, but we no longer need to rebuild it after each change to the source code. The System
is a reference to the SystemJS library we just installed through NPM. It takes care of the import statements, loading those dependencies with Ajax requests.
You may notice the references to react
and react-dom
. We import these in main.js
, but where do they come from? Browserify fetches them out of the node_modules
folder. When we skip the Browserify step, we need to let SystemJS know where to find them.
The easiest place to find these files is at https://facebook.github.io/react. Click on the download button, extract the archive, and copy the JS
files in the build
folder to where they are referenced in the HTML page.
The ReactJS website is a great place to download ReactJS, and find documentation about how you can use it:

- Python網(wǎng)絡(luò)爬蟲從入門到實(shí)踐(第2版)
- oreilly精品圖書:軟件開發(fā)者路線圖叢書(共8冊(cè))
- 概率成形編碼調(diào)制技術(shù)理論及應(yīng)用
- Visual FoxPro程序設(shè)計(jì)習(xí)題集及實(shí)驗(yàn)指導(dǎo)(第四版)
- 區(qū)塊鏈底層設(shè)計(jì)Java實(shí)戰(zhàn)
- Mastering C++ Multithreading
- Spring+Spring MVC+MyBatis從零開始學(xué)
- Visual Basic程序設(shè)計(jì)習(xí)題與上機(jī)實(shí)踐
- .NET 4.5 Parallel Extensions Cookbook
- 零基礎(chǔ)學(xué)Python編程(少兒趣味版)
- PHP與MySQL權(quán)威指南
- 程序員的成長(zhǎng)課
- Java程序設(shè)計(jì)及應(yīng)用開發(fā)
- JavaScript Mobile Application Development
- Getting Started with the Lazarus IDE