react js初级入门hello world
React JS离线转换依赖于npm(基于mac):
1、检查是否安装node:node -v
2、安装homebrew,打开终端,执行以下命令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
3、安装node:brew install node,执行该命令后,node和npm自动安装好
4、在项目文件下,执行npm init,生成package.json文件
5、先安装命令行工具:npm install -g react-tools
6、将自己的js/helloworld.js转成标准的JavaScript文件:jsx --watch js/ bulid/
7、html Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello React!</title>
<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
</head>
<body>
<div id="example"></div>
<script src="build/helloworld.js"></script>
</body>
</html>
8、Js/helloworld.js Code
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('example')
);
一旦修改了自己的helloworld.js文件,build/helloworld.js文件会自动随之生成
以上就简单的在页面打印出Hello,world!
参考:http://reactjs.cn/react/docs/getting-started.html