Skip to content

Commit 67ec345

Browse files
committed
perf: react profile
1 parent 72917b8 commit 67ec345

File tree

14 files changed

+418
-323
lines changed

14 files changed

+418
-323
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
"import/no-unresolved": 0,
2727
"import/no-extraneous-dependencies": 0,
2828
"no-plusplus": 0,
29+
"no-param-reassign": 0,
2930
}
3031
}

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ yarn deploy || npm run deploy
3333
- [x] 打包构建: Babel Webpack(4.x)
3434
- [x] 热更新: webpack-server 赋能
3535
- [x] 包管理: Yarn || Npm
36-
- [x] UI 库: React & React-Dom(16.4.0)
36+
- [x] UI 库: React & React-Dom(16.5.x)
3737
- [x] UI 组件: Antd(3.x)
3838
- [x] 路由: react-router(4.x)、react-router-redux
3939
- [x] JS: ES6、ES7
@@ -42,16 +42,14 @@ yarn deploy || npm run deploy
4242
- [x] Ajax: Fetch
4343
- [x] 跨域: 基于 CORS 实现
4444
- [x] 代码校验: Eslint(Airbnb)
45-
- [ ] [css 模块化](https://github.com/MuYunyun/reactSPA/issues/52)
46-
- [ ] [网关](https://github.com/MuYunyun/gateway): 一个 IOC 的简单 demo,有时间填坑
45+
- [ ] [网关](https://github.com/MuYunyun/gateway): ioc 模式,有时间填坑
4746

4847
### Optimize
4948

5049
* [压缩打包优化](https://github.com/MuYunyun/reactSPA/issues/53)
50+
* [css 模块化](https://github.com/MuYunyun/reactSPA/issues/52)
5151

52-
### Document
53-
54-
提到过该项目的文章,未来会迭代。
52+
### Articles
5553

5654
* [使用 React 全家桶搭建一个后台管理系统](http://muyunyun.cn/posts/9bfbdbf4/)
5755
* [redux middleware 源码分析](http://muyunyun.cn/posts/7f9a92dc/)

config/env.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (!NODE_ENV) {
1313
}
1414

1515
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
16-
var dotenvFiles = [
16+
const dotenvFiles = [
1717
`${paths.dotenv}.${NODE_ENV}.local`,
1818
`${paths.dotenv}.${NODE_ENV}`,
1919
// Don't include `.env.local` for `test` environment
@@ -51,32 +51,19 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '')
5151
.map(folder => path.resolve(appDirectory, folder))
5252
.join(path.delimiter)
5353

54-
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
55-
// injected into the application via DefinePlugin in Webpack configuration.
56-
const REACT_APP = /^REACT_APP_/i
57-
5854
// 获取客户端环境
59-
function getClientEnvironment(publicUrl) {
60-
const raw = Object.keys(process.env)
61-
.filter(key => REACT_APP.test(key))
62-
.reduce(
63-
(env, key) => {
64-
env[key] = process.env[key]
65-
return env
66-
},
67-
{
68-
NODE_ENV: process.env.NODE_ENV || 'development',
69-
PUBLIC_URL: publicUrl,
70-
}
71-
)
72-
// Stringify all values so we can feed into Webpack DefinePlugin
55+
function getClientEnvironment() {
56+
const raw = {
57+
NODE_ENV: process.env.NODE_ENV || 'development',
58+
// PUBLIC_URL: publicUrl,
59+
}
60+
7361
const stringified = {
7462
'process.env': Object.keys(raw).reduce((env, key) => {
7563
env[key] = JSON.stringify(raw[key])
7664
return env
7765
}, {}),
7866
}
79-
8067
return { raw, stringified }
8168
}
8269

config/webpack.config.dev.js

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ const path = require('path')
33
const webpack = require('webpack')
44
const HtmlWebpackPlugin = require('html-webpack-plugin')
55
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
6-
// const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin')
7-
// const eslintFormatter = require('react-dev-utils/eslintFormatter')
86
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin')
9-
const getClientEnvironment = require('./env')
107
const AnalyzeWebpackPlugin = require('analyze-webpack-plugin').default
8+
const getClientEnvironment = require('./env')
119
const paths = require('./paths')
1210

1311
const publicPath = '/'
@@ -60,22 +58,6 @@ module.exports = {
6058
module: { // https://doc.webpack-china.org/configuration/module/
6159
strictExportPresence: true,
6260
rules: [
63-
// 在 babel 解析前进行 eslint 校验
64-
// {
65-
// test: /\.(js|jsx)$/,
66-
// enforce: 'pre',
67-
// use: [
68-
// {
69-
// options: {
70-
// formatter: eslintFormatter,
71-
// eslintPath: require.resolve('eslint'),
72-
73-
// },
74-
// loader: require.resolve('eslint-loader'),
75-
// },
76-
// ],
77-
// include: paths.appSrc,
78-
// },
7961
{
8062
// 使用第一个规则匹配
8163
oneOf: [
@@ -189,13 +171,13 @@ module.exports = {
189171
// 当开启 HMR 的时候使用该插件会显示模块的相对路径,建议用于开发环境。作用没理解~
190172
// new webpack.NamedModulesPlugin(),
191173
// 区别开发模式和发布模式的全局变量
192-
new webpack.DefinePlugin(env.stringified),
174+
new webpack.DefinePlugin(Object.assign({}, env.stringified, {
175+
ENABLE_DEVTOOLS: true,
176+
})),
193177
// This is necessary to emit hot updates (currently CSS only):
194178
new webpack.HotModuleReplacementPlugin(),
195179
// 防止大小写错误
196180
new CaseSensitivePathsPlugin(),
197-
// 在 npm install 新的依赖后自动刷新
198-
// new WatchMissingNodeModulesPlugin(paths.appNodeModules),
199181
// 优化 moment.js 库的体积,https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
200182
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
201183
new AnalyzeWebpackPlugin(), // 输入 http://localhost:3000/analyze.html 查看相应信息,从而进行优化

config/webpack.config.prod.js

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const webpack = require('webpack')
44
const HtmlWebpackPlugin = require('html-webpack-plugin')
55
const ManifestPlugin = require('webpack-manifest-plugin')
66
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin')
7-
// const eslintFormatter = require('react-dev-utils/eslintFormatter')
87
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin')
98
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
109
const paths = require('./paths')
@@ -21,9 +20,6 @@ const env = getClientEnvironment(publicUrl)
2120
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
2221
throw new Error('Production builds must have NODE_ENV=production.')
2322
}
24-
25-
// const cssFilename = 'static/css/[name].[contenthash:8].css'
26-
2723
// 优先体积
2824
module.exports = {
2925
mode: 'production',
@@ -67,21 +63,6 @@ module.exports = {
6763
module: {
6864
strictExportPresence: true,
6965
rules: [
70-
// {
71-
// test: /\.(js|jsx)$/,
72-
// enforce: 'pre',
73-
// use: [
74-
// {
75-
// options: {
76-
// formatter: eslintFormatter,
77-
// eslintPath: require.resolve('eslint'),
78-
79-
// },
80-
// loader: require.resolve('eslint-loader'),
81-
// },
82-
// ],
83-
// include: paths.appSrc,
84-
// },
8566
{
8667
oneOf: [
8768
{
@@ -180,27 +161,6 @@ module.exports = {
180161
},
181162
],
182163
},
183-
// optimization: {
184-
// cacheGroups: {
185-
// vendor1: {
186-
// chunks: 'all',
187-
// test: /[\\/]node_modules[\\/](react|react-dom|antd)[\\/]/,
188-
// name: 'vendor1',
189-
// maxAsyncRequests: 5,
190-
// priority: 10,
191-
// enforce: true,
192-
// },
193-
// vendor2: {
194-
// chunks: 'all',
195-
// test: /[\\/]node_modules[\\/]/,
196-
// name: 'vendor2',
197-
// maxAsyncRequests: 5,
198-
// priority: 9,
199-
// enforce: true,
200-
// reuseExistingChunk: true,
201-
// },
202-
// },
203-
// },
204164
plugins: [
205165
new HtmlWebpackPlugin({
206166
inject: true,
@@ -218,7 +178,9 @@ module.exports = {
218178
minifyURLs: true,
219179
},
220180
}),
221-
new webpack.DefinePlugin(env.stringified),
181+
new webpack.DefinePlugin(Object.assign({}, env.stringified, {
182+
ENABLE_DEVTOOLS: false,
183+
})),
222184
// Generate a manifest file which contains a mapping of all asset filenames
223185
// to their corresponding output file so that tools can pick it up without
224186
// having to parse `index.html`.
@@ -239,7 +201,6 @@ module.exports = {
239201
if (message.indexOf('Skipping static resource') === 0) {
240202
return
241203
}
242-
console.log(message)
243204
},
244205
minify: true,
245206
// For unknown URLs, fallback to the index page

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"homepage": "http://muyunyun.cn/reactSPA/",
1919
"dependencies": {
20-
"antd": "^3.2.1",
20+
"antd": "^3.9.3",
2121
"babel-plugin-on-demand-loading": "^0.0.9",
2222
"diana": "0.5.1",
2323
"draftjs-to-html": "^0.7.2",
@@ -30,8 +30,8 @@
3030
"moment": "^2.18.1",
3131
"photoswipe": "^4.1.2",
3232
"prop-types": "^15.6.2",
33-
"react": "^16.4.2",
34-
"react-dom": "^16.4.2",
33+
"react": "^16.5.2",
34+
"react-dom": "^16.5.2",
3535
"react-draft-wysiwyg": "^1.10.0",
3636
"react-loadable": "^5.5.0",
3737
"react-redux": "^5.0.5",
@@ -90,7 +90,7 @@
9090
"style-loader": "0.18.2",
9191
"sw-precache-webpack-plugin": "0.11.5",
9292
"url-loader": "0.5.9",
93-
"webpack": "^4.20.0",
93+
"webpack": "^4.20.2",
9494
"webpack-cli": "^2.0.6",
9595
"webpack-dev-server": "^3.0.0-beta.1",
9696
"webpack-manifest-plugin": "2.0.0-rc.2",

src/client/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ const history = createHistory()
1212

1313
const store = configureStore()
1414

15+
/* eslint-disable */
1516
ReactDOM.render(
1617
<Provider store={store}>
1718
<ConnectedRouter history={history}>
1819
<div>
1920
{ routes }
20-
{process.env.NODE_ENV === 'development' ? <DevTools /> : ''}
21+
{ENABLE_DEVTOOLS ? <DevTools /> : ''}
2122
</div>
2223
</ConnectedRouter>
2324
</Provider>,

src/common/pages/home/accessNum/index.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ import {
55
import EchartsViews from './EchartsViews'
66

77
const AccessNum = () => (
8-
<div>
9-
<Col span={8}>
10-
<div className="cloud-box">
11-
<Card>
12-
<div className="pb-m">
13-
<h3>访问量统计</h3>
14-
<small>最近7天用户访问量</small>
15-
</div>
16-
<span className="card-tool"><Icon type="sync" /></span>
17-
<EchartsViews />
18-
</Card>
19-
</div>
20-
</Col>
21-
</div>)
8+
<Col span={8}>
9+
<div className="cloud-box">
10+
<Card>
11+
<div className="pb-m">
12+
<h3>访问量统计</h3>
13+
<small>最近7天用户访问量</small>
14+
</div>
15+
<span className="card-tool"><Icon type="sync" /></span>
16+
<EchartsViews />
17+
</Card>
18+
</div>
19+
</Col>)
2220

2321
export default AccessNum

src/common/pages/home/buildSiteLog/index.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,28 @@ import {
44
} from 'antd'
55

66
const BuildSiteLog = () => (
7-
<div>
8-
<Col span={8}>
9-
<div className="cloud-box">
10-
<Card>
11-
<div className="pb-m">
12-
<h3>建站日志</h3>
13-
<small>2个待完成,1个正在进行中</small>
14-
</div>
15-
<span className="card-tool"><Icon type="sync" /></span>
16-
<Timeline>
17-
<Timeline.Item color="#108ee9">
18-
<p>更多模块开发中</p>
19-
</Timeline.Item>
20-
<Timeline.Item color="red">
21-
<p>使用ts重构(正在开发)</p>
22-
</Timeline.Item>
23-
<Timeline.Item color="green">封装Ajax实现跨域请求</Timeline.Item>
24-
<Timeline.Item color="green">引人Redux,Fetch</Timeline.Item>
25-
<Timeline.Item color="green">引人Less,React-Router(4.x)</Timeline.Item>
26-
<Timeline.Item color="green">初始化项目</Timeline.Item>
27-
</Timeline>
28-
</Card>
29-
</div>
30-
</Col>
31-
</div>)
7+
<Col span={8}>
8+
<div className="cloud-box">
9+
<Card>
10+
<div className="pb-m">
11+
<h3>建站日志</h3>
12+
<small>2个待完成,1个正在进行中</small>
13+
</div>
14+
<span className="card-tool"><Icon type="sync" /></span>
15+
<Timeline>
16+
<Timeline.Item color="#108ee9">
17+
<p>更多模块开发中</p>
18+
</Timeline.Item>
19+
<Timeline.Item color="red">
20+
<p>使用ts重构</p>
21+
</Timeline.Item>
22+
<Timeline.Item color="green">模块化探索</Timeline.Item>
23+
<Timeline.Item color="green">封装Ajax实现跨域请求</Timeline.Item>
24+
<Timeline.Item color="green">引人Redux,Fetch</Timeline.Item>
25+
<Timeline.Item color="green">引人Less,React-Router(4.x)</Timeline.Item>
26+
</Timeline>
27+
</Card>
28+
</div>
29+
</Col>)
3230

3331
export default BuildSiteLog

src/common/pages/home/index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import './index.less'
99

1010
const Index = () => (
1111
<Row gutter={16}>
12-
<LeftTop />
13-
<ProFinish />
14-
<BuildSiteLog />
15-
<MsgBanner />
16-
<AccessNum />
12+
<div style={{ overflow: 'hidden' }}>
13+
<LeftTop />
14+
<ProFinish />
15+
</div>
16+
<div>
17+
<BuildSiteLog />
18+
<MsgBanner />
19+
<AccessNum />
20+
</div>
1721
</Row>
1822
)
1923

0 commit comments

Comments
 (0)