Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.development

This file was deleted.

1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API_BASE_URL=
1 change: 0 additions & 1 deletion .env.production

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
/build

# Environment files
.env.local
.env.*
!.env.example

#others
yarn-error.log
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ This Template is for building React efficient React Frontend Apps. It uses moder

- Package Manager : 🧶 yarn Version 1.22.5
- Compiler : 🤖 Babel Version 7
- Framework : 🔥 React Project (TypeScript) Verison 17
- Framework : 🔥 React Project (TypeScript) Version 17
- Bundler : 📦 Webpack Version 5
- Styling : 💅 styled-components (supports traditional css/scss)
- Component Preview : 🔖 Storybook with Webpack 5 bundler
- Development : eslint, prettier, editorconfig
- Development : 🎨 eslint, prettier, editorconfig
- Testing : 🧪 React Testing Library with Jest
- Environment Variable - ⚙️ Support with environment files
- .env.local - varialbles with secrets (should include in .gitignore)
- .env.development - variables required while development
- .env.production - variables required for production
- Environment Variable -
- APP_ENV - Current build / running environment. Default is local.
- Environment Configuration - ⚙️ Support with deployment specific environment files
- .env.example - Define a schema of what variables should be defined in .env.{your_APP_ENV}. It throws an error if all values are not configured
- Access the env variable in javascript using process.env.<your-env-variable>
- Code Spiltting : 🖖 Webpack Split Chunks (basic)
- Tree Shaking : 🌲 Webpack Terser Plugin (basic)
- Clone Branch react-router if you want to use [react-router-dom](https://reactrouter.com/)

43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Tushar Mistry",
"license": "ISC",
"scripts": {
"start": "webpack serve --config webpack/webpack.config.js --env env=dev",
"start": "cross-env APP_ENV=local webpack serve --config webpack/webpack.config.js --env env=dev",
"build": "webpack --config webpack/webpack.config.js --env env=prod",
"analyze": "webpack --config webpack/webpack.config.js --env env=prod --analyze",
"lint": "eslint --fix \"./src/**/*.{js,jsx,ts,tsx,scss,css,json}\"",
Expand All @@ -30,17 +30,17 @@
"styled-components"
],
"dependencies": {
"@babel/core": "^7.14.0",
"@babel/plugin-transform-runtime": "^7.13.15",
"@babel/preset-env": "^7.14.1",
"@babel/core": "^7.14.2",
"@babel/plugin-transform-runtime": "^7.14.2",
"@babel/preset-env": "^7.14.2",
"@babel/preset-react": "^7.13.13",
"@babel/preset-typescript": "^7.13.0",
"@babel/runtime": "^7.14.0",
"@svgr/webpack": "^5.5.0",
"babel-loader": "^8.2.2",
"copy-webpack-plugin": "^8.1.1",
"css-loader": "^5.2.4",
"dotenv": "^9.0.2",
"dotenv-webpack": "^7.0.2",
"html-webpack-plugin": "^5.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand All @@ -58,28 +58,29 @@
"@storybook/addon-links": "^6.2.9",
"@storybook/builder-webpack5": "^6.2.9",
"@storybook/react": "^6.2.9",
"@testing-library/jest-dom": "5.12.0",
"@testing-library/react": "11.2.6",
"@types/jest": "26.0.23",
"@types/react": "17.0.5",
"@types/react-dom": "17.0.4",
"@types/styled-components": "5.1.9",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"@types/jest": "^26.0.23",
"@types/react": "^17.0.5",
"@types/react-dom": "^17.0.5",
"@types/styled-components": "^5.1.9",
"@typescript-eslint/eslint-plugin": "^4.23.0",
"@typescript-eslint/parser": "^4.23.0",
"eslint": "7.26.0",
"cross-env": "^7.0.3",
"eslint": "^7.26.0",
"eslint-config-airbnb": "18.2.1",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-jest": "24.3.6",
"eslint-plugin-jsx-a11y": "6.4.1",
"eslint-plugin-prettier": "3.4.0",
"eslint-plugin-react": "7.23.2",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.23.1",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-react": "^7.23.2",
"eslint-plugin-react-hooks": "^4.2.0",
"husky": "6.0.0",
"jest": "^26.6.3",
"lint-staged": "11.0.0",
"netlify-cli": "3.29.4",
"prettier": "2.3.0",
"lint-staged": "^11.0.0",
"netlify-cli": "^3.29.15",
"prettier": "^2.3.0",
"react-refresh": "^0.10.0",
"ts-jest": "26.5.6",
"ts-node": "9.1.1",
Expand Down
4 changes: 1 addition & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet" />
<title>React-Template</title>
</head>
<body>
<div id="root"></div>
<link href="https://fonts.googleapis.com/css2?family=Nunito&display=swap" rel="stylesheet" />
</body>
</html>
23 changes: 8 additions & 15 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const dotenv = require('dotenv');
const { DefinePlugin } = require('webpack');
const DotEnv = require('dotenv-webpack');

let envKeys = {};
try {
const env = dotenv.config({ path: path.join(__dirname, '..', '.env.local') }).parsed;
const APP_ENV = process.env.APP_ENV || 'local';

envKeys = Object.keys(env).reduce((prev, next) => {
// eslint-disable-next-line no-param-reassign
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
console.log('Loaded Environment variable from .env.local');
} catch (error) {
console.log('.env.local File Not Found');
}
const DotEnvWebPackPlugin = new DotEnv({
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs. (useful for CI purposes)
safe: true, // load '.env.example' to verify the '.env' variables are all set.
path: path.join(__dirname, '..', `.env.${APP_ENV}`),
});

module.exports = {
entry: path.resolve(__dirname, '..', './src/index.tsx'),
Expand Down Expand Up @@ -80,6 +73,6 @@ module.exports = {
new CopyWebpackPlugin({
patterns: [{ from: path.join(__dirname, 'source'), to: 'dest', noErrorOnMissing: true }],
}),
new DefinePlugin(envKeys),
DotEnvWebPackPlugin,
],
};
19 changes: 1 addition & 18 deletions webpack/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
/* eslint-disable no-console */
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const { DefinePlugin } = require('webpack');
const dotenv = require('dotenv');
const path = require('path');

let envKeys = {};
try {
const env = dotenv.config({ path: path.join(__dirname, '..', '.env.development') }).parsed;

envKeys = Object.keys(env).reduce((prev, next) => {
// eslint-disable-next-line no-param-reassign
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
console.log('Loaded environment variable from .env.development');
} catch (error) {
console.log('.env.development file Not Found');
}

module.exports = {
mode: 'development',
devServer: { hot: true },
devtool: 'cheap-module-source-map',
stats: 'minimal',
// incase failures for webpack react-refresh add HotModuleReplacementPlugin
plugins: [new ReactRefreshWebpackPlugin(), new DefinePlugin(envKeys)],
plugins: [new ReactRefreshWebpackPlugin()],
};
18 changes: 0 additions & 18 deletions webpack/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
/* eslint-disable no-console */
const dotenv = require('dotenv');
const path = require('path');
const { DefinePlugin } = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');

let envKeys = {};
try {
const env = dotenv.config({ path: path.join(__dirname, '..', '.env.production') }).parsed;
envKeys = Object.keys(env).reduce((prev, next) => {
// eslint-disable-next-line no-param-reassign
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
console.log('Loaded environment variable from .env.production');
} catch (error) {
console.log('.env.production file Not Found');
}

module.exports = {
mode: 'production',
devtool: 'source-map',
Expand All @@ -31,5 +14,4 @@ module.exports = {
}),
],
},
plugins: [new DefinePlugin(envKeys)],
};
Loading