Skip to content

Commit f26f252

Browse files
committed
my react hello world
0 parents  commit f26f252

File tree

7 files changed

+189
-0
lines changed

7 files changed

+189
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

App.jsx

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
class App extends React.Component {
4+
render() {
5+
return (
6+
<div>simon, helloworld!!!</div>
7+
);
8+
}
9+
}
10+
11+
export default App;

README.md

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# react.js hello world
2+
---
3+
first, you should install node and npm.
4+
5+
1. create directory
6+
`mkdir helloworld && cd helloworld`
7+
8+
2. init npm
9+
`npm init`
10+
11+
3. install webpack and webpack-dev-server
12+
`npm install webpack webpack-dev-server --save`
13+
14+
4. install react and react-dom
15+
`npm install react react-dom --save`
16+
17+
5. install babel etc.
18+
`npm install babel-core babel-loader babel-preset-react babel-preset-es2015 --save`
19+
20+
6. add start scripts to package.json
21+
```javascript
22+
"scripts": {
23+
"test": "echo \"Error: no test specified\" && exit 1",
24+
"start": "webpack-dev-server --hot"
25+
}
26+
```
27+
28+
7. touch webpack.config.js
29+
```javascript
30+
var config = {
31+
entry: './main.js',
32+
33+
output: {
34+
path: './',
35+
filename: 'index.js'
36+
},
37+
38+
devServer: {
39+
inline: true,
40+
port: 7777
41+
},
42+
43+
module: {
44+
loaders: [
45+
{
46+
test: /\.jsx?$/,
47+
exclude: /node_modules/,
48+
loader: 'babel',
49+
query: {
50+
presets: ['es2015', 'react']
51+
}
52+
}
53+
]
54+
}
55+
}
56+
57+
module.exports = config;
58+
```
59+
60+
8. touch index.html
61+
```html
62+
<!DOCTYPE html>
63+
<html>
64+
<head>
65+
<meta charset="utf-8">
66+
<title>react helloworld</title>
67+
</head>
68+
<body>
69+
<div id="app"></div>
70+
<script src="index.js" charset="utf-8"></script>
71+
</body>
72+
</html>
73+
```
74+
75+
9. touch App.jsx
76+
```javascript
77+
import React from 'react';
78+
79+
class App extends React.Component {
80+
render() {
81+
return (
82+
<div>simon, helloworld!!!</div>
83+
);
84+
}
85+
}
86+
87+
export default App;
88+
```
89+
90+
10. touch main.js
91+
```javascript
92+
import React from 'react';
93+
import ReactDOM from 'react-dom';
94+
95+
import App from './App.jsx';
96+
97+
ReactDOM.render(<App />, document.getElementById('app'));
98+
```
99+
100+
11. start server
101+
`npm start`
102+
103+
12. open browser: http://localhost:7777
104+
105+
---
106+
if you clone this repository to local, just `npm install` and `npm start`.

index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>react helloworld</title>
6+
</head>
7+
<body>
8+
<div id="app"></div>
9+
<script src="index.js" charset="utf-8"></script>
10+
</body>
11+
</html>

main.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
4+
import App from './App.jsx';
5+
6+
ReactDOM.render(<App />, document.getElementById('app'));

package.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "helloworld",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "webpack-dev-server --hot"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"babel-core": "^6.9.1",
14+
"babel-loader": "^6.2.4",
15+
"babel-preset-es2015": "^6.9.0",
16+
"babel-preset-react": "^6.5.0",
17+
"react": "^15.1.0",
18+
"react-dom": "^15.1.0",
19+
"webpack": "^1.13.1",
20+
"webpack-dev-server": "^1.14.1"
21+
}
22+
}

webpack.config.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
var config = {
2+
// 打包的入口文件
3+
entry: './main.js',
4+
5+
// 配置打包结果,path定义输出文件夹,filename定义打包结果文件的名称
6+
output: {
7+
path: './',
8+
filename: 'index.js'
9+
},
10+
11+
// 设置服务器端口号
12+
devServer: {
13+
inline: true,
14+
port: 7777
15+
},
16+
17+
// 配置模块的处理逻辑,用loaders定义加载器
18+
module: {
19+
loaders: [
20+
{
21+
test: /\.jsx?$/,
22+
exclude: /node_modules/,
23+
loader: 'babel',
24+
query: {
25+
presets: ['es2015', 'react']
26+
}
27+
}
28+
]
29+
}
30+
}
31+
32+
module.exports = config;

0 commit comments

Comments
 (0)