Skip to content

Commit b5baf2a

Browse files
committed
updated 01 Hello React
1 parent b9a2120 commit b5baf2a

File tree

12 files changed

+67
-74
lines changed

12 files changed

+67
-74
lines changed

01 HelloReact/.babelrc

-10
This file was deleted.

01 HelloReact/package.json

-35
This file was deleted.

01_HelloReact/.babelrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"useBuiltIns": "entry"
7+
}
8+
]
9+
]
10+
}

01_HelloReact/package.json

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "reactbysample",
3+
"version": "1.0.0",
4+
"description": "In this sample we setup the basic plumbing to \"build\" our project and launch it in a dev server.",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "webpack-dev-server --mode development --inline --hot --open",
8+
"build": "webpack --mode development",
9+
"test": "echo \"Error: no test specified\" && exit 1"
10+
},
11+
"author": "",
12+
"license": "ISC",
13+
"devDependencies": {
14+
"@babel/cli": "^7.1.2",
15+
"@babel/core": "^7.1.2",
16+
"@babel/polyfill": "^7.0.0",
17+
"@babel/preset-env": "^7.1.0",
18+
"@types/react": "^16.4.16",
19+
"@types/react-dom": "^16.0.9",
20+
"awesome-typescript-loader": "^5.2.1",
21+
"babel-loader": "^8.0.4",
22+
"css-loader": "^1.0.0",
23+
"file-loader": "^2.0.0",
24+
"html-webpack-plugin": "^3.2.0",
25+
"mini-css-extract-plugin": "^0.4.3",
26+
"style-loader": "^0.23.1",
27+
"typescript": "^3.1.1",
28+
"url-loader": "^1.1.1",
29+
"webpack": "^4.20.2",
30+
"webpack-cli": "^3.1.2",
31+
"webpack-dev-server": "^3.1.9"
32+
},
33+
"dependencies": {
34+
"react": "^16.5.2",
35+
"react-dom": "^16.5.2"
36+
}
37+
}

01 HelloReact/readme.md renamed to 01_HelloReact/readme.md

+1-11
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,7 @@ export const HelloComponent = () => {
6868
<h2>Hello component !</h2>
6969
);
7070
}
71-
```
72-
Side note: in ES6, this can written as
73-
74-
```jsx
75-
import * as React from 'react';
76-
77-
export const HelloComponent = () => (
78-
<h2>Hello component !</h2>
79-
);
80-
81-
```
71+
```
8272

8373
- Wire up this component by using `react-dom` under [./src/main.tsx](./src/main.tsx) (we have to rename this file extension from `ts` to `tsx` and replace the content).
8474

File renamed without changes.
File renamed without changes.

01 HelloReact/src/index.html renamed to 01_HelloReact/src/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ <h1>Sample app</h1>
1010
<div id="root"></div>
1111
</div>
1212
</body>
13-
</html>
13+
</html>

01_HelloReact/src/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
document.write("Hello from main.ts !");
File renamed without changes.

01 HelloReact/tsconfig.json renamed to 01_HelloReact/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
"exclude": [
1515
"node_modules"
1616
]
17-
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
let path = require('path');
2-
let HtmlWebpackPlugin = require('html-webpack-plugin');
3-
let MiniCssExtractPlugin = require('mini-css-extract-plugin');
4-
let webpack = require('webpack');
1+
var HtmlWebpackPlugin = require('html-webpack-plugin');
2+
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
3+
var webpack = require('webpack');
4+
var path = require('path');
55

6-
let basePath = __dirname;
6+
var basePath = __dirname;
77

88
module.exports = {
99
context: path.join(basePath, "src"),
1010
resolve: {
1111
extensions: ['.js', '.ts', '.tsx']
1212
},
13-
entry: [
14-
'./main.tsx',
15-
'../node_modules/bootstrap/dist/css/bootstrap.css'
16-
],
13+
entry: ['@babel/polyfill',
14+
'./main.tsx'
15+
],
1716
output: {
1817
path: path.join(basePath, 'dist'),
19-
filename: 'bundle.js',
18+
filename: 'bundle.js'
2019
},
2120
devtool: 'source-map',
2221
devServer: {
@@ -25,7 +24,7 @@ module.exports = {
2524
host: 'localhost',
2625
port: 8080,
2726
stats: 'errors-only'
28-
},
27+
},
2928
module: {
3029
rules: [
3130
{
@@ -34,8 +33,9 @@ module.exports = {
3433
loader: 'awesome-typescript-loader',
3534
options: {
3635
useBabel: true,
37-
},
38-
},
36+
"babelCore": "@babel/core", // needed for Babel v7
37+
},
38+
},
3939
{
4040
test: /\.css$/,
4141
use: [MiniCssExtractPlugin.loader, "css-loader"]
@@ -47,7 +47,7 @@ module.exports = {
4747
name: 'assets/img/[name].[ext]?[hash]'
4848
}
4949
},
50-
],
50+
],
5151
},
5252
plugins: [
5353
//Generate index.html in /dist => https://github.com/ampedandwired/html-webpack-plugin
@@ -60,5 +60,5 @@ module.exports = {
6060
filename: "[name].css",
6161
chunkFilename: "[id].css"
6262
}),
63-
],
64-
};
63+
],
64+
};

0 commit comments

Comments
 (0)