Skip to content

Commit 95a70ab

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 668521c + 648647b commit 95a70ab

File tree

12 files changed

+1203
-231
lines changed

12 files changed

+1203
-231
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ React-Typescript-Webpack was config with React, Typescript and Webpack without C
2626

2727
# Documentation
2828

29-
[https://thaind97git.github.io/react-typescript-webpack/](https://thaind97git.github.io/react-typescript-webpack/)
29+
Full documentation [here](https://thaind97git.github.io/react-typescript-webpack/)
3030

3131
## License
3232

config/env.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const dotenvFiles = [
3030
// since normally you expect tests to produce the same
3131
// results for everyone
3232
// NODE_ENV !== 'test' && `${paths.dotenv}.local`,
33-
`${paths.dotenv}.${NODE_ENV}`,
33+
`${paths.dotenv}`,
3434
// paths.dotenv,
3535
].filter(Boolean);
3636

config/jest/routeMock.js

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const fs = require('fs');
2+
const path = require('../paths');
3+
4+
const { appSrc } = path;
5+
const featuresDir = `${appSrc}/features`;
6+
7+
const routeFileName = 'route.ts';
8+
9+
const RouteModules = [];
10+
function readFolder(dir) {
11+
const files = fs.readdirSync(dir);
12+
files.forEach(file => {
13+
const filePath = `${dir}/${file}`;
14+
const stat = fs.statSync(filePath);
15+
if (stat.isDirectory()) {
16+
readFolder(filePath);
17+
} else {
18+
if (file === routeFileName) {
19+
const route = require(filePath);
20+
RouteModules.push(route);
21+
}
22+
}
23+
});
24+
}
25+
26+
readFolder(featuresDir);
27+
28+
const appRoutes = RouteModules.reduce((prev, module) => {
29+
prev.push(...module.default);
30+
return prev;
31+
}, []);
32+
33+
module.exports = appRoutes;

docs/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
[ yarn or npm run ] build
5252
```
5353

54-
2. Setup env for production mode by create new file `.env.production`
54+
2. Setup env for production mode by create new file `.env`
5555

5656
3. Run project at build directory
5757
- Using pm2: `[ yarn or npm run ] start-pm2`
@@ -121,7 +121,9 @@
121121

122122
_- 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)._
123123

124-
_- 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._
124+
_- ~~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.~~_
125+
126+
_- Now, I'm supported auto import route for jest (check at `config/jest/routeMock.js)`_
125127

126128
## Write new component
127129

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@babel/plugin-transform-runtime": "^7.13.10",
4242
"@babel/preset-env": "^7.13.9",
4343
"@babel/preset-react": "^7.12.13",
44-
"@svgr/webpack": "^5.5.0",
44+
"@svgr/webpack": "^6.2.1",
4545
"@testing-library/jest-dom": "^5.11.10",
4646
"@testing-library/react": "^12.0.0",
4747
"@types/enzyme": "^3.10.9",

src/constants/env.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const { NODE_ENV, API_SERVER_URL, PORT } = process.env;
2+
3+
export default {
4+
NodeEnv: NODE_ENV,
5+
ApiServerUrl: API_SERVER_URL,
6+
Port: PORT,
7+
};

src/jest.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const config = {
1717
'^.+\\.(css|less|scss)$': '<rootDir>/config/jest/cssMock.js',
1818
'^@/static/(.*)$': '<rootDir>/public/static/$1',
1919
'^@/(.*)$': '<rootDir>/src/$1',
20+
'^.+\\/features/\\*\\*/route.ts$': '<rootDir>/config/jest/routeMock.js',
2021
},
2122
};
2223

src/locales/i18n.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import i18n from 'i18next';
22
import { initReactI18next } from 'react-i18next';
3+
import env from '@/constants/env';
34

45
import resources, { langs } from './resources';
5-
const isProduction = process.env.NODE_ENV === 'production';
6+
const isProduction = env.NodeEnv === 'production';
67

78
i18n.use(initReactI18next).init({
89
resources,

src/services/axios-base.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import env from '@/constants/env';
12
import { getHeaders } from '@/utils';
23

34
import axios from 'axios';
45
// Make an 'instance' of axios
56
const instance = axios.create({
67
// .. where we make our configurations
7-
baseURL: process.env.API_SERVER_URL,
8+
baseURL: env.ApiServerUrl,
89
});
910

1011
// Where you would set stuff like your 'Authorization' header, etc ...

webpack/webpack.common.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = {
5252
},
5353
{
5454
test: /\.svg$/,
55+
issuer: /\.[jt]sx?$/,
5556
use: ['@svgr/webpack'],
5657
},
5758
{
@@ -69,10 +70,23 @@ module.exports = {
6970
{
7071
test: /\.(woff|woff2|eot|ttf|otf)$/i,
7172
type: 'asset/resource',
73+
generator: {
74+
filename: 'static/fonts/[hash][ext][query]',
75+
},
76+
},
77+
{
78+
test: /\.(png|jpg|jpeg)$/i,
79+
type: 'asset/resource',
80+
generator: {
81+
filename: 'static/images/[hash][ext][query]',
82+
},
7283
},
7384
{
74-
test: /\.(png|jpg|jpeg|gif)$/i,
85+
test: /\.(gif)$/i,
7586
type: 'asset/resource',
87+
generator: {
88+
filename: 'static/gifs/[hash][ext][query]',
89+
},
7690
},
7791
],
7892
},

webpack/webpack.prod.js

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const ImageminWebpack = require('image-minimizer-webpack-plugin');
1313
const paths = require('../config/paths');
1414
const { appBuild, appPublic, appHtml } = paths;
1515

16+
const imageTypeIgnoreCopy = ['.png', '.jpg', '.jpeg', '.gif', '.svg'];
1617
// Source maps are resource heavy and can cause out of memory issue for large source files.
1718

1819
module.exports = merge(common, {
@@ -29,6 +30,12 @@ module.exports = merge(common, {
2930
{
3031
from: path.resolve(appPublic, 'static'),
3132
to: path.resolve(appBuild, 'static'),
33+
globOptions: {
34+
ignore: [
35+
...imageTypeIgnoreCopy.map(ext => `**/images/*/*${ext}`),
36+
'**/fonts/**',
37+
],
38+
},
3239
toType: 'dir',
3340
},
3441
],
@@ -67,6 +74,7 @@ module.exports = merge(common, {
6774
filename: 'static/js/[name].[chunkhash].js',
6875
// There are also additional JS chunk files if you use code splitting.
6976
chunkFilename: 'static/js/[name].[chunkhash].chunk.js',
77+
clean: true,
7078
},
7179
optimization: {
7280
nodeEnv: 'production',

0 commit comments

Comments
 (0)