Skip to content

Commit bb116d4

Browse files
author
Eran Machiels
authored
Merge pull request #1 from machielsdev/feature/setup-react
Feature/setup react
2 parents c2369f8 + 02dbc95 commit bb116d4

File tree

9 files changed

+196
-14
lines changed

9 files changed

+196
-14
lines changed

package-lock.json

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

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
"scripts": {
77
"build": "tsc -p tsconfig-build.json",
88
"test": "jest --config=jest.config.json",
9-
"test-coverage": "jest --config=jest.config.json --collectCoverage"
9+
"test-coverage": "jest --config=jest.config.json --collectCoverage",
10+
"dev": "webpack serve --config www/webpack.config.js"
1011
},
1112
"author": "Eran Machiels",
1213
"license": "ISC",
1314
"devDependencies": {
14-
"typescript": "^4.0.3",
1515
"@babel/plugin-proposal-class-properties": "^7.10.4",
1616
"@babel/preset-env": "^7.11.0",
1717
"@babel/preset-react": "^7.10.4",
@@ -23,14 +23,22 @@
2323
"@types/react-is": "^16.7.1",
2424
"@typescript-eslint/eslint-plugin": "^4.5.0",
2525
"@typescript-eslint/parser": "^4.5.0",
26+
"dart-sass": "^1.25.0",
2627
"enzyme": "^3.11.0",
2728
"enzyme-adapter-react-16": "^1.15.3",
2829
"eslint": "^7.7.0",
2930
"eslint-plugin-react": "^7.20.6",
3031
"flush-promises": "^1.0.2",
32+
"react-dom": "^17.0.1",
3133
"react-scripts": "^4.0.0",
3234
"react-test-renderer": "^17.0.1",
3335
"ts-loader": "^8.0.2",
34-
"webpack-cli": "^4.1.0"
36+
"typescript": "^4.0.3",
37+
"webpack-cli": "^4.1.0",
38+
"webpack-dev-server": "^3.11.0"
39+
},
40+
"dependencies": {
41+
"clsx": "^1.1.1",
42+
"react": "^17.0.1"
3543
}
3644
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"exclude": [
4444
"node_modules",
4545
"dist",
46-
"setupTests.ts"
46+
"setupTests.ts",
47+
"www"
4748
]
4849
}

www/.env

Whitespace-only changes.

www/public/favicon.ico

3.78 KB
Binary file not shown.

www/public/index.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="shortcut icon" href="./favicon.ico" />
6+
<meta
7+
name="viewport"
8+
content="width=device-width, initial-scale=1, shrink-to-fit=no"
9+
/>
10+
<meta name="theme-color" content="#000000" />
11+
<meta
12+
name="description"
13+
content="Web site created using create-react-app"
14+
/>
15+
<!--
16+
manifest.json provides metadata used when your web app is installed on a
17+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
18+
-->
19+
<link rel="manifest" href="./manifest.json" />
20+
<!--
21+
Notice the use of %PUBLIC_URL% in the tags above.
22+
It will be replaced with the URL of the `public` folder during the build.
23+
Only files inside the `public` folder can be referenced from the HTML.
24+
25+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
26+
work correctly both with client-side routing and a non-root public URL.
27+
Learn how to configure a non-root public URL by running `npm run build`.
28+
-->
29+
<title>React App</title>
30+
</head>
31+
<body>
32+
<noscript>You need to enable JavaScript to run this app.</noscript>
33+
<div id="root"></div>
34+
<!--
35+
This HTML file is a template.
36+
If you open it directly in the browser, you will see an empty page.
37+
38+
You can add webfonts, meta tags, or analytics to this file.
39+
The build step will place the bundled scripts into the <body> tag.
40+
41+
To begin the development, run `npm start` or `yarn start`.
42+
To create a production bundle, use `npm run build` or `yarn build`.
43+
-->
44+
</body>
45+
</html>

www/public/robots.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *

www/src/index.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as React from 'react';
2+
import * as ReactDom from 'react-dom';
3+
4+
ReactDom.render(
5+
null,
6+
document.getElementById('root')
7+
);

www/webpack.config.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// eslint-disable-next-line @typescript-eslint/no-var-requires
2+
const webpack = require('webpack');
3+
const path = require('path');
4+
const HtmlWebpackPlugin = require('html-webpack-plugin');
5+
const WebpackManifestPlugin = require('webpack-manifest-plugin');
6+
const dotenv = require('dotenv');
7+
8+
/**
9+
* Load env file and parse config, to be used when building the app
10+
* @returns {webpack.DefinePlugin}
11+
*/
12+
const setEnvVars = () => {
13+
const env = dotenv.config({
14+
path: './www/.env'
15+
}).parsed;
16+
17+
// loop over the keys and place them in the process.env namespace
18+
const keys = Object.keys(env).reduce((prev, next) => {
19+
prev[`process.env.${next}`] = JSON.stringify(env[next]);
20+
return prev;
21+
}, {});
22+
23+
return new webpack.DefinePlugin(keys);
24+
};
25+
26+
module.exports = {
27+
entry: {
28+
main: './www/src/index.tsx'
29+
},
30+
module: {
31+
rules: [
32+
{
33+
test: /\.ts(x|)?$/,
34+
use: 'babel-loader',
35+
exclude: /node_modules/
36+
}, {
37+
test: /\.[s|]css$/,
38+
use: [{
39+
loader: 'style-loader'
40+
}, {
41+
loader: 'css-loader'
42+
}, {
43+
loader: 'sass-loader',
44+
options: {
45+
implementation: require('dart-sass')
46+
}
47+
}]
48+
}, {
49+
test: /\.(png|svg|jpg|jpeg|gif|ico|woff2?)$/,
50+
exclude: /node_modules/,
51+
use: ['file-loader?name=[name].[ext]'] // ?name=[name].[ext] is only necessary to preserve the original file name
52+
}
53+
]
54+
},
55+
resolve: {
56+
extensions: ['.tsx', '.ts', '.js', '.jsx']
57+
},
58+
plugins: [
59+
new HtmlWebpackPlugin({
60+
template: './www/public/index.html',
61+
favicon: path.resolve(__dirname, 'public', 'favicon.ico')
62+
}),
63+
new WebpackManifestPlugin(),
64+
setEnvVars()
65+
],
66+
output: {
67+
filename: '[name].[hash].js',
68+
path: path.resolve(__dirname, 'www', 'public'),
69+
publicPath: '/'
70+
},
71+
mode: 'development',
72+
devServer: {
73+
host: 'localhost',
74+
port: 3000,
75+
open: true,
76+
historyApiFallback: true,
77+
publicPath: '/',
78+
hot: true
79+
}
80+
};

0 commit comments

Comments
 (0)