Skip to content

Commit b72042e

Browse files
committed
update webpack config, add page use redux.
1 parent 129e615 commit b72042e

File tree

19 files changed

+154
-35
lines changed

19 files changed

+154
-35
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
REACT_APP_NAME=SHERRY

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@babel/preset-env": "^7.12.17",
3636
"@babel/preset-react": "^7.12.13",
3737
"@babel/preset-typescript": "^7.12.17",
38+
"@types/chalk": "^2.2.0",
3839
"@types/classnames": "^2.2.11",
3940
"@types/react": "^17.0.2",
4041
"@types/react-dom": "^17.0.1",
@@ -48,6 +49,7 @@
4849
"autoprefixer": "^10.2.4",
4950
"babel-loader": "^8.2.2",
5051
"babel-plugin-import": "^1.13.3",
52+
"chalk": "^4.1.0",
5153
"clean-webpack-plugin": "^3.0.0",
5254
"cross-env": "^7.0.3",
5355
"css-loader": "^5.0.2",
@@ -66,7 +68,7 @@
6668
"prettier": "^2.2.1",
6769
"style-loader": "^2.0.0",
6870
"terser-webpack-plugin": "^5.1.1",
69-
"typescript": "^4.1.5",
71+
"typescript": "4.1.3",
7072
"webpack": "^5.23.0",
7173
"webpack-cli": "^4.5.0",
7274
"webpack-dev-server": "^3.11.2",

public/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8">
5-
<title>react</title>
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title><%= htmlWebpackPlugin.options.title %></title>
68
</head>
79
<body>
810

scripts/helper.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
const fs = require('fs');
22
const path = require('path');
3+
const os = require('os');
34
const dotenv = require('dotenv');
45

56
const NODE_ENV = process.env.NODE_ENV;
6-
const REACT_APP_REGEXP = /^REACT_APP_/i;
7-
8-
if (!NODE_ENV) {
9-
throw new Error('必须指定 NODE_ENV');
10-
}
117

128
const rootPath = path.resolve(__dirname, '..');
139

1410
function getProcessEnv() {
11+
const REACT_APP_REGEXP = /^REACT_APP_/i;
12+
13+
if (!NODE_ENV) {
14+
throw new Error('必须指定 NODE_ENV');
15+
}
16+
1517
const result = {};
1618

1719
const dotenvFiles = [
@@ -31,7 +33,9 @@ function getProcessEnv() {
3133
});
3234
}
3335
});
36+
3437
result.NODE_ENV = NODE_ENV;
38+
3539
return result;
3640
}
3741

@@ -49,10 +53,23 @@ function processSize(size) {
4953
};
5054
}
5155

52-
56+
function getLocalIP() {
57+
const interfaces = os.networkInterfaces();
58+
for (let devName in interfaces) {
59+
if (interfaces.hasOwnProperty(devName)) {
60+
let iface = interfaces[devName];
61+
for (let i = 0; i < iface.length; i++) {
62+
let alias = iface[i];
63+
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
64+
return alias.address;
65+
}
66+
}
67+
}
68+
}
69+
}
5370

5471
module.exports = {
5572
getProcessEnv,
5673
processSize,
74+
getLocalIP,
5775
};
58-

scripts/plugins/PackingGenerateFilePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class PackingGenerateFilePlugin {
77
let contentList = [];
88
// statObj.size() 的单位是 bit
99
Object.entries(assets).forEach(([filename, statObj]) => {
10-
const { size, unit } = helper.processSize(statObj.size())
10+
const { size, unit } = helper.processSize(statObj.size());
1111
contentList.push({filename, size: `${size}${unit}` });
1212
});
1313
console.table(contentList);

scripts/webpack.config.dev.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
const path = require('path');
2+
const webpack = require('webpack');
23
const {merge} = require('webpack-merge');
34
const HtmlWebpackPlugin = require('html-webpack-plugin');
4-
const webpack = require('webpack');
5+
const chalk = require('chalk');
56

67
const baseConfig = require('./webpack.config');
78
const pkg = require('../package.json');
9+
const helper = require('./helper');
10+
11+
const defaultConfig = {
12+
port: process.env.REACT_APP_PORT || 18000
13+
};
814

915
module.exports = merge(baseConfig, {
1016
mode: 'development',
17+
1118
devtool: 'source-map',
19+
1220
devServer: {
13-
port: 18000,
21+
port: defaultConfig.port,
1422
hot: true,
1523
compress: true,
16-
transportMode: 'ws',
24+
clientLogLevel: 'silent',
1725
contentBase: path.resolve(__dirname, '../public'),
1826
historyApiFallback: {
1927
index: path.resolve(__dirname, '../public/index.html'),
2028
disableDotRule: true,
2129
},
22-
before(app, server) {
23-
30+
after(app, server) {
31+
console.log(chalk.green(`❤ ${pkg.name} server startup successfully, please visit...`));
32+
console.log(chalk.green(`❤ http://localhost:${defaultConfig.port}`));
33+
console.log(chalk.green(`❤ http://${helper.getLocalIP()}:${defaultConfig.port}`));
2434
}
2535
},
2636

scripts/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
new webpack.EnvironmentPlugin(envObj),
3737
],
3838

39-
stats: 'errors-only',
39+
stats: 'minimal',
4040

4141
};
4242

src/assets/images/avatar.jpg

30.9 KB
Loading

src/global.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module '*.jpg';
2+
declare module '*.jpeg';
3+
declare module '*.png';
4+
declare module '*.gif';
5+
declare module '*.svg';
6+
declare module '*.bmp';
7+
declare module '*.ttf';
8+
declare module '*.woff';
9+
declare module '*.woff2';

src/index.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ import history from '@/store/history';
99
import store from '@/store';
1010
import '@/assets/style/global.less';
1111

12-
function Home() {
13-
return (
14-
<div>
15-
home page
16-
</div>
17-
);
18-
}
12+
const Home = React.lazy(() => import('@/pages/home/index'));
1913

2014
ReactDOM.render(
2115
<Provider store={store}>

0 commit comments

Comments
 (0)