Skip to content

Commit 47fac3b

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 38b5479 + c7a84cf commit 47fac3b

File tree

6 files changed

+1147
-303
lines changed

6 files changed

+1147
-303
lines changed

.huskyinstall

-71
This file was deleted.

README.md

+8-231
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<div align="center">
2+
<p>
3+
<a href="https://github.com/thaind97git/react-typescript-webpack/issues" target="_blank" rel="noopener"><img src="https://img.shields.io/github/issues/thaind97git/react-typescript-webpack" data-origin="https://img.shields.io/github/issues/thaind97git/react-typescript-webpack" alt="Git issue"></a>
4+
<a href="https://github.com/thaind97git/react-typescript-webpack/network/members" target="_blank" rel="noopener"><img src="https://img.shields.io/github/forks/thaind97git/react-typescript-webpack" data-origin="https://img.shields.io/github/forks/thaind97git/react-typescript-webpack" alt="Git forks"></a>
5+
<a href="https://github.com/thaind97git/react-typescript-webpack/stargazers" target="_blank" rel="noopener"><img src="https://img.shields.io/github/stars/thaind97git/react-typescript-webpack" data-origin="https://img.shields.io/github/stars/thaind97git/react-typescript-webpack" alt="Git star"></a>
6+
<a href="https://github.com/thaind97git/react-typescript-webpack/blob/main/LICENSE" target="_blank" rel="noopener"><img src="https://img.shields.io/github/license/thaind97git/react-typescript-webpack" data-origin="https://img.shields.io/github/license/thaind97git/react-typescript-webpack" alt="Git MIT"></a>
7+
</p>
28
<img src="./public/static/images/banner.png" alt="react typescript webpack starter" />
39
</div>
410
<br />
@@ -18,238 +24,9 @@ React-Typescript-Webpack was config with React, Typescript and Webpack without C
1824

1925
---
2026

21-
## Quick Start
27+
# Documentation
2228

23-
For Development:
24-
25-
1. Clone this repo to your local machine using:
26-
27-
```javascript
28-
git clone git@github.com:thaind97git/react-typescript-webpack.git
29-
```
30-
31-
2. Change the current working directory to the project:
32-
33-
```javascript
34-
cd react-typescript-webpack
35-
```
36-
37-
3. Install dependencies:
38-
39-
```javascript
40-
[ yarn or npm install ]
41-
```
42-
43-
4. At this point you can run `npm run dev` or `yarn dev` to run project with development mode
44-
45-
_Now, your browser will auto open at `http://127.0.0.1:3000`_
46-
47-
For Production:
48-
49-
1. Run command to build:
50-
51-
```javascript
52-
[ yarn or npm run ] build
53-
```
54-
55-
2. Setup env for production mode by create new file `.env.production`
56-
57-
3. Run project at build directory
58-
- Using pm2: `[ yarn or npm run ] start-pm2`
59-
- Run with terminal: `[ yarn or npm run ] start`
60-
61-
---
62-
63-
## Features
64-
65-
- [x] React hook
66-
- [x] Webpack 5
67-
- [x] Typescript
68-
- [x] Sass
69-
- [x] Redux-thunk
70-
- [ ] Redux-saga
71-
- [x] Jest
72-
- [x] Axios
73-
- [x] I18n
74-
- [x] React-router
75-
- [x] Alias
76-
- [x] Hot reload
77-
- [x] Eslint
78-
- [x] Prettier and Husky
79-
80-
---
81-
82-
## How to using
83-
84-
- Router:
85-
86-
- Create new feature at `src/features/<feature-name/>`
87-
- Create a `route.ts` inside `src/features/<feature-name/>` and export default an array match with rules:
88-
89-
```javascript
90-
import { lazy } from 'react';
91-
const Component = lazy(() => import('./path-to-component'));
92-
93-
export default [
94-
{
95-
/*
96-
* name of a route
97-
* using to apply key react when generate routes
98-
* required for declare
99-
*/
100-
name: 'name',
101-
/*
102-
* path of route
103-
*/
104-
path: '/path-name',
105-
/*
106-
* using as exact in react-router
107-
*/
108-
exact: true,
109-
/*
110-
* dynamic render layout for each route
111-
* header: false -> route will auto hide header
112-
* if this rendered, don't need to declare
113-
* control this inside `src/store/slices/layoutSlice` with more section
114-
*/
115-
layout: {
116-
header: false,
117-
footer: false,
118-
},
119-
/*
120-
* component rendered inside route
121-
*/
122-
component: Component,
123-
},
124-
];
125-
```
126-
127-
_- You don't need do anything else after create and modify `route.ts` because i'm using [import-glob](https://www.npmjs.com/package/import-glob) to auto import (check at `webpack/webpack.common.js` for plugin, `src/router/index.ts` and `src/layouts/main/index.tsx` for using)._
128-
129-
_- If you don't want to use auto import or <b>using project with jest</b>, just using the code that i'm commented. Because i'm not yet support auto import for jest._
130-
131-
- Write new component
132-
133-
- Create new folder at `src/components/<component-name/>`
134-
- Create an `index.tsx` and `<any-name>.scss`
135-
136-
_- <b>Don't need</b> import `scss` into component, It will already merged into App.scss after you restart server._
137-
138-
_- This is a feature by using [import-glob](https://www.npmjs.com/package/import-glob) (check at `webpack/webpack.common.js` for plugin and `src/styles/App.scss` for using)_
139-
140-
_- You should use [BEM](http://getbem.com/) to write css without conflict_
141-
142-
- Using i18n
143-
144-
- Create new json file at `src/locales/resources/<file-name/>.json`
145-
- Add content follow this format into json file
146-
```javascript
147-
{
148-
"en": {
149-
"name": "Name"
150-
},
151-
"vi": {
152-
"name": "Tên"
153-
}
154-
}
155-
```
156-
- update `src/locales/resources/index.ts` like this:
157-
158-
```javascript
159-
/*
160-
* you can use other name instead `user`
161-
* this name will be used as path to key
162-
*/
163-
import user from './<file-name/>.json
164-
165-
const mergeResource: IResource = {
166-
..., // others json
167-
user
168-
};
169-
```
170-
171-
- Now inside any where, you can access to key like this:
172-
173-
```javascript
174-
const { t } = useTranslation()
175-
176-
t('user.name') will be render "Name" for `en` and "Tên" for `vi`
177-
```
178-
179-
- Call API with axios
180-
181-
```javascript
182-
import { getUser } from '@/apis/user.ts';
183-
import { setLoading } from '@/store/slices/appSlice';
184-
import { errorHandler } from '@/helpers/axios';
185-
186-
const dispatch = useDispatch();
187-
188-
// Use useCallback to memorize create func (just one time)
189-
const fetchUser = useCallback(async () => {
190-
try {
191-
// Star loading spinner
192-
dispatch(setLoading(true));
193-
194-
// fetch user
195-
const resp = await getUser();
196-
console.log(resp);
197-
} catch (error) {
198-
// display toast when error
199-
errorHandler(error);
200-
} finally {
201-
// End loading spinner
202-
dispatch(setLoading(false));
203-
}
204-
}, []);
205-
206-
useEffect(() => {
207-
// Trigger function
208-
fetchUser();
209-
}, [fetchUser]);
210-
```
211-
212-
- How to use Auth feature
213-
- If you want to build an admin page, with authorize full layout, just go to line **50** at `src/layouts/main.tsx` and use the code inside comment.
214-
- **Auth** component is a feature help authorize page by fetching profile each time page rendered.
215-
- You must have a server API to use this feature. This API with simple function like receive a header token, return user profile if token is valid and return 404 if token is expired.
216-
217-
---
218-
219-
## Tips
220-
221-
- Go to `.huskyinstall`, remove comment at <b>line 37</b> and run `[yarn or npm install]` again to apply run test when using `git push origin [ branch ]`
222-
- Go to `config/@types/[any-file-name].d.ts` to declare global type of typescript
223-
- Go to `pm2/prod.json` and change <b>"name: ~~react-webpack-typescript-starter~~ ->[other-name]"</b> to config pm2 app name
224-
- Go to `components/spinner/index.tsx` and modify jsx + css to use another loading
225-
226-
---
227-
228-
## Carefully
229-
230-
- Don't create folder with the `PascalCase`. Because it will throw error when build prod at ubuntu. I will fix it later or happy if you have a PR to fix it.
231-
```javascript
232-
Module not found: Error: Can't resolve '@/path-to-pascal-case' in '/path-to-lower-case'
233-
```
234-
235-
---
236-
237-
## Other References
238-
239-
- Webpack Plugins
240-
- [ts-loader](https://github.com/TypeStrong/ts-loader)
241-
- [import-glob](https://www.npmjs.com/package/import-glob)
242-
- [eslint-loader](https://www.npmjs.com/package/eslint-loader)
243-
- [babel-loader](https://github.com/babel/babel-loader)
244-
- [svg-loader](https://github.com/gregberge/svgr)
245-
- [sass](https://www.npmjs.com/package/sass), [sass-loader](https://www.npmjs.com/package/sass-loader)
246-
- [html-loader](https://www.npmjs.com/package/html-loader)
247-
- [alias](https://webpack.js.org/configuration/resolve/)
248-
- [webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin)
249-
- ...
250-
- [React-scripts CRA](https://github.com/facebook/create-react-app/tree/master/packages/react-scripts/config)
251-
- [Husky](https://typicode.github.io/husky/#/)
252-
- [Lint-Staged](https://github.com/okonet/lint-staged)
29+
[https://thaind97git.github.io/react-typescript-webpack/](https://thaind97git.github.io/react-typescript-webpack/)
25330

25431
## License
25532

0 commit comments

Comments
 (0)