https://andy770921.github.io/react-redux-boilerplate/
-
npm run watch
: start typescript watch mode -
npm run start
: start running dev-server -
npm run build
: build bundled JS file from src folder into dist folder -
npm run lint
: use ESLint for manually checking files inside src folder -
Fix format error on save automatically
-
Replace
<your-repo-name>
with custom relative url inside.env
PUBLIC_URL=<your-repo-name>
// e.g. PUBLIC_URL=react-redux-router
// The setting will direct React-Router to the right url
// e.g. https://andy770921.github.io/react-redux-router/
- Deploy to gh-pages branch automatically via GitHub Actions by setting ACCESS_TOKEN
-
Style setting:
<GlobalStyle>
for resetting global style in the filesrc/index.tsx
-
Route setting:
<Redirect to="/" />
for handling wrong URL path in the filesrc/app/App.tsx
-
Use the concept of Ducks pattern
-
Refer to the style guide of Redux official website, Redux in Actions
┌── .vscode # VSCode setting for ESLint auto-fix function
├── dist # Static files like HTML template and bundled JS
├── src # All source code
│ ├── app # Main component and router setting
│ ├── components # Reusable component throughout different features
│ ├── features # Classified by features
│ │ ├── firstFeature
│ │ │ ├── (Componentes) # React Components
│ │ │ └── firstFeatureTask # Redux Task in specific feature
│ │ │ including Actions, Action Creaters, Epics and Reducer
│ │ └── secondFeature
│ │ ├── (Componentes)
│ │ └── secondFeatureTask
│ ├── redux # Redux store, root action, root epics and root reducer
│ └── index.tsx # Redux Provider, add global style, and render to DOM
├── .gitignore # Exclude files from Git version contral
├── .eslintrc.js # ESLint setting
├── .env # Environment variables setting
├── README.md # README
├── package-lock.json # Lock the version of dependencies packages
├── package.json # List dependencies packages,npm scripts, project name etc.
├── webpack.config.js # Webpack setting in develop mode
├── webpack.prod-config.js # Webpack setting in production mode
└── tsconfig.json # TypeScript settings
-
npm install --save-dev dotenv
-
Add your custom
PUBLIC_URL
inside.env
PUBLIC_URL=<your-repo-name>
// e.g. PUBLIC_URL=react-redux-router
// The setting will direct React-Router to the right url
// e.g. https://andy770921.github.io/react-redux-router/
- Add
getEnv
function inwebpack.prod-config.js
plugins array for getting environment variables successfully
const path = require('path');
const webpack = require('webpack');
const dotenv = require('dotenv');
const getEnv = () => {
// call dotenv and it will return an Object with a parsed key
const env = dotenv.config().parsed;
// reduce it to a nice object, the same as before
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
return new webpack.DefinePlugin(envKeys);
}
module.exports = {
mode: 'production',
// ....
plugins: [
getEnv()
]
};
-
Add
<script>
inindex.html
and404.html
and changevar segmentCount = 1
in404.html
. Script Content Ref -
Add
basename={process.env.PUBLIC_URL}
in the props of<BrowserRouter>
inindex.tsx
-
npm install gh-pages --save-dev -g
-
Enter
gh-pages -d dist
in command line, change the source of GitHub Pages Settings into gh-pages
-
Add a personal access token and then copy the value
-
Add a Secrets key named
ACCESS_TOKEN
with the value of personal access token -
Create the file
.github/workflows/github-actions.yml
:
name: CI/CD
on:
push:
branches:
- master
jobs:
build:
runs-on: macos-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Build
run: |
npm install
npm run build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.ACCESS_TOKEN }}
publish_branch: gh-pages
publish_dir: ./dist