React
Project Template
package.json
{
"name": "app",
"version": "0.0.0",
"private": true,
"dependencies": {
"clean-webpack-plugin": "^4.0.0-alpha.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"terser-webpack-plugin": "^5.1.4",
"web-vitals": "^1.0.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/jest": "^26.0.15",
"@types/node": "^14.11.2",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"copy-webpack-plugin": "^9.0.1",
"css-loader": "^6.1.0",
"file-loader": "^6.2.0",
"gts": "^3.1.0",
"html-webpack-plugin": "^5.3.2",
"mini-css-extract-plugin": "^2.1.0",
"ts-loader": "^9.2.3",
"typescript": "^4.0.3",
"webpack": "^5.45.1",
"webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^5.8.0"
},
"scripts": {
"lint": "gts lint",
"clean": "gts clean",
"compile": "tsc",
"fix": "gts fix",
"build": "webpack --config ./webpack.prod.js",
"dev": "webpack serve --config ./webpack.dev.js"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
}
}
tsconfig.json
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "build",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"noImplicitAny": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": false,
"jsx": "react"
},
"include": [
"src",
]
}
src/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>My erf App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
src/index.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
src/App.tsx
import React from 'react';
const App = () => {
return (
<h1>Hello World</h1>
)
}
export default App;
src/index.css
webpack.common.js
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCSSExtractPlugin = require('mini-css-extract-plugin')
const path = require('path');
module.exports = {
entry: {
bundle: path.join(__dirname, 'src', 'index.tsx')
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: path.resolve(__dirname, './static') }
]
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './src/index.html'),
minify: true
}),
new MiniCSSExtractPlugin()
],
output: {
filename: 'bundle.[contenthash].js',
path: path.resolve(__dirname, './dist')
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use:
[
MiniCSSExtractPlugin.loader,
'css-loader'
]
},
{
test: /\.(jpg|png|gif|svg)$/,
use:
[
{
loader: 'file-loader',
options:
{
outputPath: 'assets/images/'
}
}
]
},
{
test: /\.(ttf|eot|woff|woff2)$/,
use:
[
{
loader: 'file-loader',
options:
{
outputPath: 'assets/fonts/'
}
}
]
}
]
}
}
webpack.dev.js
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
mode: 'development',
devtool: 'inline-source-map',
devServer: {
contentBase: './dist',
open: true,
},
});
webpack.prod.js
const { merge } = require('webpack-merge')
const common = require('./webpack.common.js')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin');
module.exports = merge(common, {
mode: 'production',
plugins:
[
new CleanWebpackPlugin(),
],
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
})
],
},
})
static/manifest.json
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
.prettierrc.js
module.exports = {
...require('gts/.prettierrc.json')
}
.eslintrc.json
{
"extends": "./node_modules/gts/"
}
.eslintignore
dist/
webpack.*.js
src/@types/images.d.ts
declare module "*.jpeg";
declare module "*.jpg";
declare module "*.gif";
declare module "*.png";
declare module "*.svg";