Skip to content

Commit 67ef6e8

Browse files
authored
Merge pull request #1 from itReverie/configuringClientSide
Basic set-up of react and specifics for the client part
2 parents 516e68e + f6575f7 commit 67ef6e8

File tree

7 files changed

+1526
-24
lines changed

7 files changed

+1526
-24
lines changed

lib/bundle.js

Whitespace-only changes.

lib/components/Index.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom'; // We need this dependency because we are interfacing with the browser
3+
4+
5+
// I have my normal class component
6+
class App extends React.Component{
7+
//Using class properties from babel Stage-2, it need babel-polyfill
8+
state={ answer:42};
9+
10+
// I am declaring a function
11+
asyncFunc = () => {
12+
return Promise.resolve(37);
13+
};
14+
15+
//It is important to label the host function as async
16+
async componentDidMount(){
17+
this.setState({answer: await this.asyncFunc()});
18+
}
19+
20+
render(){
21+
return (
22+
<h2>Hello I am a react Class component. -- {this.state.answer}</h2>
23+
);
24+
}
25+
}
26+
27+
export default App;
28+
29+
30+
// I am rendering in the DOM my app
31+
ReactDOM.render(<App/>, document.getElementById('root'));

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"homepage": "https://github.com/itReverie/itR-react-advance#readme",
2828
"scripts": {
2929
"test": "echo \"Error: no test specified\" && exit 1",
30-
"dev": "pm2 start lib/server.js --watch --interpreter babel-node"
30+
"dev": "pm2 start lib/server.js --watch --interpreter babel-node",
31+
"webpack": "webpack -d"
3132
},
3233
"babel": {
3334
"presets": [
@@ -43,11 +44,16 @@
4344
},
4445
"dependencies": {
4546
"babel-cli": "^6.26.0",
47+
"babel-loader": "^7.1.2",
48+
"babel-polyfill": "^6.26.0",
4649
"babel-preset-env": "^1.6.1",
4750
"babel-preset-react": "^6.24.1",
4851
"babel-preset-stage-2": "^6.24.1",
4952
"ejs": "^2.5.7",
5053
"express": "^4.16.2",
51-
"pm2": "^2.7.2"
54+
"pm2": "^2.7.2",
55+
"react": "^16.0.0",
56+
"react-dom": "^16.0.0",
57+
"webpack": "^3.8.1"
5258
}
5359
}

public/bundle.js

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

views/index.ejs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
<title>Advance React</title>
88
</head>
99
<body>
10-
<h2>Hello All <%= answer %> </h2>
10+
11+
<div id="root">
12+
Loading...
13+
</div>
14+
15+
<!-- Nowadays it is a good practice to make reference to just one file so we do not have multiple references -->
16+
<script src="/bundle.js" charset="UTF-8"></script>
1117
</body>
1218
</html>

webpack.config.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const path = require('path');
2+
3+
const config = {
4+
entry: [ 'babel-polyfill', './lib/components/Index.js'],
5+
output: {
6+
path: path.resolve(__dirname, 'public'),
7+
filename: 'bundle.js'
8+
},
9+
module: {
10+
rules: [
11+
{ test: /\.js/, exclude:/node_modules/, use: 'babel-loader' }
12+
]
13+
}
14+
};
15+
16+
module.exports = config;

0 commit comments

Comments
 (0)