Skip to content

Commit 3ddf4ba

Browse files
Add Webpack, babel loader, React modules
1 parent 40c0678 commit 3ddf4ba

File tree

8 files changed

+2317
-2
lines changed

8 files changed

+2317
-2
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets" : ["es2015", "react"]
3+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"vsicons.presets.angular": false
3+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
3+
class AwesomeComponent extends React.Component {
4+
5+
constructor(props) {
6+
super(props);
7+
this.state = {likesCount : 0};
8+
this.onLike = this.onLike.bind(this);
9+
}
10+
11+
onLike () {
12+
let newLikesCount = this.state.likesCount + 1;
13+
this.setState({likesCount: newLikesCount});
14+
}
15+
16+
render() {
17+
return (
18+
<div>
19+
Likes : <span>{this.state.likesCount}</span>
20+
<div><button onClick={this.onLike}>Like Me</button></div>
21+
</div>
22+
);
23+
}
24+
25+
}
26+
27+
export default AwesomeComponent;

client/app/index.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
import {render} from 'react-dom';
3+
4+
// ...
5+
import AwesomeComponent from './Components/AwesomeComponent.jsx';
6+
// ...
7+
class App extends React.Component {
8+
render () {
9+
return (
10+
<div>
11+
<p> Hello Thien Trinh Duc!</p>
12+
<AwesomeComponent />
13+
</div>
14+
);
15+
}
16+
}
17+
18+
// ...
19+
render(<App/>, document.getElementById('app'));

client/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<meta charset="utf-8">
4+
<title>React.js using NPM, Babel6 and Webpack</title>
5+
</head>
6+
<body>
7+
<div id="app" />
8+
<script src="public/bundle.js" type="text/javascript"></script>
9+
</body>
10+
</html>

client/public/bundle.js

Lines changed: 2217 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "Fetch meteo infor from other services to forecast weather for flying",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"dev": "webpack -d --watch",
9+
"build" : "webpack -p"
810
},
911
"repository": {
1012
"type": "git",
@@ -15,5 +17,15 @@
1517
"bugs": {
1618
"url": "https://github.com/thientd87/FlightForecast/issues"
1719
},
18-
"homepage": "https://github.com/thientd87/FlightForecast#readme"
20+
"homepage": "https://github.com/thientd87/FlightForecast#readme",
21+
"devDependencies": {
22+
"webpack": "^2.2.1"
23+
},
24+
"dependencies": {
25+
"babel-loader": "^6.2.10",
26+
"babel-preset-es2015": "^6.22.0",
27+
"babel-preset-react": "^6.22.0",
28+
"react": "^15.4.2",
29+
"react-dom": "^15.4.2"
30+
}
1931
}

webpack.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var webpack = require('webpack');
2+
var path = require('path');
3+
4+
var BUILD_DIR = path.resolve(__dirname, 'client/public');
5+
var APP_DIR = path.resolve(__dirname, 'client/app');
6+
7+
var config = {
8+
entry: APP_DIR + '/index.jsx',
9+
output: {
10+
path: BUILD_DIR,
11+
filename: 'bundle.js'
12+
},
13+
module : {
14+
loaders : [
15+
{
16+
test : /\.jsx?/,
17+
include : APP_DIR,
18+
loader : 'babel-loader'
19+
}
20+
]
21+
}
22+
};
23+
24+
module.exports = config;

0 commit comments

Comments
 (0)