-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
2038 lines (848 loc) · 108 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="theme-next pisces use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">
<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">
<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">
<link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">
<meta name="keywords" content="Hexo, NexT">
<meta property="og:type" content="website">
<meta property="og:title" content="bai">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="bai">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="bai">
<script type="text/javascript" id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Pisces',
version: '5.1.4',
sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
fancybox: true,
tabs: true,
motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
duoshuo: {
userId: '0',
author: '博主'
},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<link rel="canonical" href="http://yoursite.com/">
<title>bai</title>
</head>
<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container sidebar-position-left
page-home">
<div class="headband"></div>
<a href="https:/baiyunshenghaishang"><img style="position:absolute;top:0;right:0" width="149" height="149" src="https://github.blog/wp-content/uploads/2008/12/forkme_right_gray_6d6d6d.png?resize=149%2C149" class="attachment-full size-full" alt="Fork me on GitHub" data-recalc-dims="1"></a>
<header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta ">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">bai</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle"></p>
</div>
<div class="site-nav-toggle">
<button>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section">
<i class="menu-item-icon fa fa-fw fa-home"></i> <br>
首页
</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section">
<i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
标签
</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section">
<i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
归档
</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/12/04/engineer/git-commit-convention/">
<span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<meta itemprop="name" content="Zhen Huang">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</span>
<span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="bai">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/12/04/engineer/git-commit-convention/" itemprop="url">git提交记录规范</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-12-04T14:45:05+08:00">
2019-12-04
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p><code>git commit</code>是日常开发中用到最多的指令之一。一般情况下,我都是<code>git commit -m 'xxxx'</code>。之前也有稍微了解<code>git commit</code>的提交规范,但是一般都只用下<code>feat</code>表示新增功能。这两天比较闲,正好系统的梳理了一些东西。以下是对 commit message 规范的一些理解。</p>
<h1 id="为什么需要规范-commit-message"><a href="#为什么需要规范-commit-message" class="headerlink" title="为什么需要规范 commit message"></a>为什么需要规范 commit message</h1><p>commit message 现在最常用的规范应该是<a href="https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#heading=h.greljkmo14y0" target="_blank" rel="noopener">Angular 规范</a>,文档很短,有效内容只有 4-5 页 word。</p>
<p>在文档的开头,goals 提到了这套规范的目的:</p>
<ol>
<li>自动生成 CHANGELOG.md</li>
<li>区分不重要的提交</li>
<li>提供更多的信息</li>
</ol>
<p>当然,这个文档很老了,更新的 AngularJS 规范可以看<a href="https:/angular/angular/blob/master/CONTRIBUTING.md#-commit-message-guidelines" target="_blank" rel="noopener">github/AngularJS</a></p>
<h1 id="Angular-JS-commit-message-规范"><a href="#Angular-JS-commit-message-规范" class="headerlink" title="Angular JS commit message 规范"></a>Angular JS commit message 规范</h1><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><type>(<scope>): <subject></span><br><span class="line"><BLANK LINE></span><br><span class="line"><body></span><br><span class="line"><BLANK LINE></span><br><span class="line"><footer></span><br></pre></td></tr></table></figure>
<p>Angular JS 的 commit message 规范包含三部分:头部、正文、尾部。其中正文和尾部可以省略,如果有,相互之间必须有空行。</p>
<h2 id="头部"><a href="#头部" class="headerlink" title="头部"></a>头部</h2><p>其中头部包含三部分:</p>
<ol>
<li>type,操作类型。操作类型是固定的,只能从固定的列表中选择,详细见下面列表</li>
<li>scope,修改文件范围。这个是可选的,如果项目要写,就应该事先确定可以填哪些,不允许自由发挥。scope 之后应该跟冒号和空格,分隔 subject。如果没有 scope,就跟在 type 之后。</li>
<li>subject,本次修改的简单描述。注意长度控制。如果修改内容较多,应在正文中详细描述。以动词开头,结尾不需要句号</li>
</ol>
<p>type 类型</p>
<ul>
<li>build: 打包、配置修改</li>
<li>ci: 持续集成配置修改</li>
<li>docs: 修改文档</li>
<li>feat: 新增特性</li>
<li>fix: 修复 bug</li>
<li>perf: 性能优化</li>
<li>refactor: 重构</li>
<li>style: 不是 css 修改! 格式修改,如空格、逗号等。</li>
<li>test: 测试</li>
<li>revert: 回退</li>
</ul>
<h2 id="正文"><a href="#正文" class="headerlink" title="正文"></a>正文</h2><p>对提交内容的详细描述<br>以动词开头</p>
<h2 id="尾部"><a href="#尾部" class="headerlink" title="尾部"></a>尾部</h2><p>如果有不兼容的更新,需要写明<br>如果是针对某个 issue 的 fix,需要给出 issue 链接</p>
<h1 id="实际应用"><a href="#实际应用" class="headerlink" title="实际应用"></a>实际应用</h1><h2 id="限制不符合规范的-message-提交"><a href="#限制不符合规范的-message-提交" class="headerlink" title="限制不符合规范的 message 提交"></a>限制不符合规范的 message 提交</h2><p><a href="https://www.npmjs.com/package/@commitlint/cli" target="_blank" rel="noopener">@commitlint/cli</a>结合<a href="https://www.npmjs.com/package/husky" target="_blank" rel="noopener">husky</a>可以阻止不符合规范的 comit message 提交</p>
<p>使用方法:</p>
<ol>
<li><p>安装<code>@commitlint/cli</code>、<code>@commitlint/config-conventional</code>和<code>husky</code></p>
<p> <code>npm i -D @commitlint/cli @commitlint/config-conventional husky</code></p>
</li>
<li><p>项目根目录新建<code>commitlint.config.js</code>文件</p>
</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// commitlint.config.js</span></span><br><span class="line"><span class="built_in">module</span>.exports = {</span><br><span class="line"> extends: [<span class="string">"@commitlint/config-conventional"</span>]</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<ol start="3">
<li>package.json 中配置 commit-msg 钩子</li>
</ol>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">// package.json</span><br><span class="line">{</span><br><span class="line"> // 其它配置</span><br><span class="line"> "husky": {</span><br><span class="line"> "hooks": {</span><br><span class="line"> "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>这样,在执行 git commit 时,如果提交的内容不符合<code>@commitlint/config-conventional</code>,就无法提交成功</p>
<h3 id="为什么使用-commitlint-config-conventional而不是-commitlint-config-angular。"><a href="#为什么使用-commitlint-config-conventional而不是-commitlint-config-angular。" class="headerlink" title="为什么使用@commitlint/config-conventional而不是@commitlint/config-angular。"></a>为什么使用<code>@commitlint/config-conventional</code>而不是<code>@commitlint/config-angular</code>。</h3><p>主要是因为 angular 规范对于 build 的定义有一些歧义,实际使用中 build 一般用于表示打包,而修改打包配置文件使用 chore</p>
<h2 id="commitizen"><a href="#commitizen" class="headerlink" title="commitizen"></a>commitizen</h2><p><a href="https://www.npmjs.com/package/commitizen" target="_blank" rel="noopener">commitizen</a> 是一个生成符合规范 commit message 的工具。</p>
<p>使用方法:</p>
<p>全局安装 commitizen<br><code>npm i -g commitizen</code></p>
<p>然后安装<a href="https://www.npmjs.com/package/cz-conventional-changelog" target="_blank" rel="noopener">cz-conventional-changelog</a></p>
<p>在<code>package.json</code>中配置</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">// package.json</span><br><span class="line">{</span><br><span class="line"> // 其它配置</span><br><span class="line"> "config": {</span><br><span class="line"> "commitizen": {</span><br><span class="line"> "path": "cz-conventional-changelog"</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>然后在使用<code>git commit</code>的地方使用<code>git cz</code>替代就可以了</p>
<h2 id="自动生成-CHANGELOG"><a href="#自动生成-CHANGELOG" class="headerlink" title="自动生成 CHANGELOG"></a>自动生成 CHANGELOG</h2><p><a href="https:/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-cli" target="_blank" rel="noopener">conventional-changelog-cli</a>可以根据 commit 记录自动生成 CHANGELOG</p>
<p>有两点要求</p>
<ol>
<li>commit message 符合 angular 规范</li>
<li>正确设置 git tag 和 package.json 的 version,否则无法识别哪些提交时当前版本的</li>
</ol>
<p>使用方式</p>
<ol>
<li>安装<code>conventional-changelog-cli</code></li>
</ol>
<p><code>npm install -D conventional-changelog-cli</code></p>
<ol start="2">
<li>在 package.json 中增加 scripts</li>
</ol>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">// package.json</span><br><span class="line">{</span><br><span class="line"> <span class="attr">"scripts"</span>: {</span><br><span class="line"> <span class="attr">"changelog"</span>: <span class="string">"conventional-changelog -p angular -i CHANGELOG.md -s"</span></span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>执行<code>npm run changelog</code><br>这种方式不会覆盖 CHANGELOG.md 之前的内容,而是在最前面增加这个版本的修改。只会加入 feat 和 fix 的内容</p>
<p>涉及版本号修改以及 git tag,正确的工作流程应该是</p>
<ol>
<li>版本内容修改</li>
<li>修改版本号</li>
<li>生成 CHANGELOG</li>
<li>git commit</li>
<li>git tag</li>
<li>git push</li>
</ol>
<h2 id="关于-commit-粒度"><a href="#关于-commit-粒度" class="headerlink" title="关于 commit 粒度"></a>关于 commit 粒度</h2><p>前面规范中讲过,每次提交都需要指定一个 type,那么如果一次修改中包含多个 type 的内容怎么办。</p>
<p>不应该这样做。</p>
<p>每一次 commit 的提交的内容应该只包含一个功能,不要同时修改多个功能。</p>
<p>这样提交的内容比较清晰明了,对 codereview 也比较友好。</p>
<p>google 在其公开的<a href="https:/google/eng-practices/blob/master/review/developer/small-cls.md" target="_blank" rel="noopener">Google Engineering Practices Documentation</a>对这个问题做了详细描述</p>
<p>也可以看<a href="https:/xindoo/eng-practices-cn" target="_blank" rel="noopener">谷歌工程实践-中文翻译版</a></p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/28/engineer/webpack-04/">
<span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<meta itemprop="name" content="Zhen Huang">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</span>
<span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="bai">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/11/28/engineer/webpack-04/" itemprop="url">webpack构建速度与体积优化</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-28T20:40:01+08:00">
2019-11-28
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>提到优化,一般都是下面几个流程</p>
<ol>
<li>确定优化目标和指标,指标有时候很容易,有时候会很复杂。因为目标是定性的,而指标必须量化。</li>
<li>获取现有数据。主要是为了发现问题,确认优化方向</li>
<li>确认优化方案,执行。</li>
<li>比对优化前后数据,确认优化效果。给领导汇报。</li>
</ol>
<p>任何没有目标的优化,都是耍流氓。</p>
<p>具体到 webpack 优化,目标是提高 webpack 的构建速度,缩小构建后文件大小。</p>
<p>下文会详细讲解检测构建速度和构建体积以及优化方案。</p>
<h1 id="构建速度与体积检测"><a href="#构建速度与体积检测" class="headerlink" title="构建速度与体积检测"></a>构建速度与体积检测</h1><h2 id="stats"><a href="#stats" class="headerlink" title="stats"></a>stats</h2><p>最简单的衡量打包速度和打包文件体积的方法可以使用 webpack 内置的 stats,在不配置 stats 的情况下,webpack 打包完成后会显示打包的时间以及每个文件的大小。<br><img src="/images/webpack-04.1.jpg" alt="stats"></p>
<p>这种方式最简单,但是缺点也很明显。粒度太粗。只显示了整个项目的打包时间和每个文件的大小,而不能分析是哪个步骤打包慢或者一个大文件包含了哪些内容。</p>
<p>所以 stats 一般只用来对粗略性的评估 webpack 的打包结果。想要更细致的评估 webpack 的打包,就必须有更详细的数据。</p>
<h2 id="构建速度检测"><a href="#构建速度检测" class="headerlink" title="构建速度检测"></a>构建速度检测</h2><p><a href="https://www.npmjs.com/package/speed-measure-webpack-plugin" target="_blank" rel="noopener">speed-measure-webpack-plugin</a>检测 webpack 各个 loader、plugin 的耗时,并按时间排序。<br><img src="/images/webpack-04.2.jpg" alt="speed-measure-webpack-plugin效果图片"><br>图中时间较长会显示红色,一般表示需要优化,当然,还看具体情况。</p>
<h3 id="使用方式"><a href="#使用方式" class="headerlink" title="使用方式"></a>使用方式</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// webpack.config.js</span></span><br><span class="line"><span class="keyword">const</span> SpeedMeasurePlugin = <span class="built_in">require</span>(<span class="string">"speed-measure-webpack-plugin"</span>)</span><br><span class="line"><span class="keyword">const</span> smp = <span class="keyword">new</span> SpeedMeasurePlugin()</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> webpackConfig = {</span><br><span class="line"> <span class="comment">// webpack 配置</span></span><br><span class="line"> stats: <span class="string">"errors-only"</span> <span class="comment">// 建议优化时开启</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = smp.wrap(webpackConfig)</span><br></pre></td></tr></table></figure>
<p>由于 stats 默认会显示构建时间等,这种情况下建议将 stats 设置为<code>errors-only</code>,只显示错误</p>
<h2 id="构建体积检测"><a href="#构建体积检测" class="headerlink" title="构建体积检测"></a>构建体积检测</h2><p>构建体积检测可以使用插件<a href="https://www.npmjs.com/package/webpack-bundle-analyzer" target="_blank" rel="noopener">webpack-bundle-analyzer</a><br><img src="/images/webpack-04.3.jpg" alt="webpack-bundle-analyzer效果图片"></p>
<p>该插件会启动一个本地服务,展示打包后各个文件的大小,以及组成部分的大小。<br>比如从上图我们可以知道为什么 vendor.js 会这么大,然后具体优化。</p>
<h3 id="使用方式-1"><a href="#使用方式-1" class="headerlink" title="使用方式"></a>使用方式</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// webpack.config.js</span></span><br><span class="line"><span class="keyword">const</span> { BundleAnalyzerPlugin } = <span class="built_in">require</span>(<span class="string">"webpack-bundle-analyzer"</span>)</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = {</span><br><span class="line"> <span class="comment">// 其它配置</span></span><br><span class="line"> plugins: [</span><br><span class="line"> <span class="comment">// 其它插件</span></span><br><span class="line"> <span class="keyword">new</span> BundleAnalyzerPlugin()</span><br><span class="line"> ]</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h1 id="优化方法"><a href="#优化方法" class="headerlink" title="优化方法"></a>优化方法</h1>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/28/engineer/webpack-03/">
<span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<meta itemprop="name" content="Zhen Huang">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</span>
<span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="bai">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/11/28/engineer/webpack-03/" itemprop="url">可维护的webpack配置</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-28T20:39:57+08:00">
2019-11-28
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/28/engineer/webpack-02/">
<span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<meta itemprop="name" content="Zhen Huang">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</span>
<span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="bai">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/11/28/engineer/webpack-02/" itemprop="url">webpack进阶用法</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-28T20:39:54+08:00">
2019-11-28
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/28/engineer/webpack-01/">
<span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<meta itemprop="name" content="Zhen Huang">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</span>
<span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="bai">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/11/28/engineer/webpack-01/" itemprop="url">webpack基础用法</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-28T20:39:23+08:00">
2019-11-28
</time>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<p>本系列文章是对极客时间课程–<a href="https://time.geekbang.org/course/intro/190" target="_blank" rel="noopener">玩转 webpack</a> 的总结。<br>章节上基本按照玩转 webpack 的章节</p>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/11/21/engineer/babel/">
<span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
<meta itemprop="name" content="Zhen Huang">
<meta itemprop="description" content="">
<meta itemprop="image" content="/images/avatar.jpg">
</span>
<span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
<meta itemprop="name" content="bai">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a class="post-title-link" href="/2019/11/21/engineer/babel/" itemprop="url">babel</a></h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建于" itemprop="dateCreated datePublished" datetime="2019-11-21T15:47:10+08:00">
2019-11-21
</time>
</span>
</div>
</header>