Skip to content

Commit

Permalink
fix webpack:stat config
Browse files Browse the repository at this point in the history
  • Loading branch information
shfshanyue committed Jul 22, 2019
1 parent 0b23265 commit 5be6889
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,30 @@ $ npm run stat

今天(2019/07/22)觉得很有必要把优化打包体积的过程给记录一下,至于以前的优化记录,如 `antd``lodash` 依赖的移除,就不大详细记录了。

### ~350KB: 初始大小
### 191.64KB/242.74KB
记录时使用 `webpack-bundle-analyzer` 这个包分析打包体积,并且把每次的报告页面放在 `/static` 下,报告的命名为 `${date}-${commit}`

大致记录每次打包后服务端和客户端 `js` 总体积,以及首屏各项参数以及各种关键事件 (关键事件与机器,网络等也有很大相关性,仅做参考)。

### 00: ~350KB

刚开始写了两个页面,并且加上 `lodash``antd` 后的初始大小

### 01: 191.64KB/242.74KB

去除 `lodash``antd` 依赖,使打包体积大幅减小。这一步其实在半年前就已经做了,紧接着随后又写了很多页面与组件,所以在去除两者依赖后,真实的打包体积比现在还有缩减。

+ [Server Stat](https://shici.xiange.tech/2019-07-22-25305f34/server.html)
+ [Client Stat](https://shici.xiange.tech/2019-07-22-25305f34/client.html)
+ [Server Stat](https://shici.xiange.tech/static/2019-07-22-25305f34/server.html)
+ [Client Stat](https://shici.xiange.tech/static/2019-07-22-25305f34/client.html)

### 176.51KB/245.02KB
### 02: 176.51KB/245.02KB

集中 `gql` 管理后,在浏览器模式下可以把所有的 `query` 都是用 `loader` 打到 `common.js` 中,而这些零散的 `query` 在以前被按需加载时重复打包多次。

+ [Server Stat](https://shici.xiange.tech/2019-07-22-99d0dd58/server.html)
+ [Client Stat](https://shici.xiange.tech/2019-07-22-99d0dd58/client.html)
+ [commit](https://github.com/shfshanyue/shici/commit/99d0dd58eac0f5af7271626c82d3815bb7af943a)
+ [Server Stat](https://shici.xiange.tech/static/2019-07-22-99d0dd58/server.html)
+ [Client Stat](https://shici.xiange.tech/static/2019-07-22-99d0dd58/client.html)
+ NetWwork statusBar: 18 requests | 223 KB transferred | 715 KB resources | Finish: 734 ms
+ Event: DCL 156.6 ms | FP 183.1 ms | FCP 183.1 ms | FMP 183.1 ms | Load 691.7 ms

## 相关思考与文章

Expand Down
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = withLess({
if (process.env.ANALYZE) {
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: path.resolve(__dirname, `${new Date().toJSON().substr(0, 10)}-${process.env.COMMIT}`, isServer ? 'server.html' : 'client.html')
reportFilename: path.resolve(__dirname, `static/${new Date().toJSON().substr(0, 10)}-${process.env.COMMIT}`, isServer ? 'server.html' : 'client.html')
}))
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "next build",
"ncu": "ncu",
"start": "NODE_ENV=production node server.js",
"stat": "COMMIT=$(git rev-parse --verify HEAD | cut -c 1-8) ANALYZE=1 next build"
"stat": "COMMIT=$(git rev-parse --short HEAD) ANALYZE=1 next build"
},
"dependencies": {
"@types/next": "^8.0.6",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5be6889

Please sign in to comment.