-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfe-tools.html
More file actions
executable file
·289 lines (264 loc) · 9.44 KB
/
fe-tools.html
File metadata and controls
executable file
·289 lines (264 loc) · 9.44 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>你不知道的几个前端小工具</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css" id="theme">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section class="center">
<h2>你不知道的几个前端小工具</h2>
<img height="238" data-src="images/1.png" alt="title">
<p>
<small><a href="http://codeigniter.org.cn" target="_blank">Hex</a> 为您分享 / Github: <a href="https://github.com/hex-ci" target="_blank">@hex-ci</a></small>
</p>
</section>
<section>
<h2>目录</h2>
<ul>
<li>前端编译工具</li>
<li>自动化部署工具</li>
<li class="fragment">附赠内容 😆</li>
</ul>
</section>
<section>
<h3>前端自动化编译工具</h3>
<p>基于 Gulp 开发,主要包括:</p>
<ul style="font-size: 0.9em">
<li style="color:#42affa">合并文件(两种合并方式)</li>
<li>图片压缩优化</li>
<li>CSS 预处理和压缩</li>
<li>JS 预处理和压缩</li>
<li>代码格式和规范检查</li>
<li>资源文件添加版本号</li>
<li>内联 JS 和 CSS 压缩</li>
<li style="color:#42affa">资源发布到 CDN</li>
<li>自动生成 SourceMap</li>
<li style="color:#42affa">增量编译</li>
</ul>
</section>
<section>
<h3>合并文件</h3>
<p>第一种方式</p>
<pre><code class="hljs">
<!-- [javascript] -->
<script src="/static/js/a.js"></script>
<script src="/static/js/b.js"></script>
<script src="/static/js/c.js"></script>
<script src="/static/js/d.js"></script>
<!-- [/javascript] -->
</code></pre>
<div class="fragment">
<p style="font-size:60%">将会生成一个合并后的文件,并替换成类似这样:</p>
<pre><code class="hljs">
<script src="/static/js/com_cb_xxxxxxxxx.js"></script>
</code></pre>
</div>
</section>
<section>
<h3>合并文件</h3>
<p>第二种方式</p>
<pre><code class="hljs">
<script src="/static/js/lib.js"></script>
</code></pre>
<pre><code class="hljs">
// lib.js
(function() {
var srcPath = '/static/js/';
document.write('<script src="' + srcPath + 'a.js"><\/script>');
document.write('<script src="' + srcPath + 'b.js"><\/script>');
document.write('<script src="' + srcPath + 'c.js"><\/script>');
document.write('<script src="' + srcPath + 'd.js"><\/script>');
}());
</code></pre>
</section>
<section>
<h3>资源添加版本号</h3>
<pre><code class="hljs">
<script src="/static/js/demo.js"></script>
</code></pre>
<pre><code class="hljs">
<script src="/static/js/demo.js?v=cf6d21e.js"></script>
</code></pre>
</section>
<section>
<h3>内联压缩</h3>
<pre><code class="hljs">
<body>
<script type="text/javascript">
function demo() {
.....
}
</script>
</body>
</code></pre>
<pre><code class="hljs">
<body>
<script type="text/javascript">function demo(){.....}</script>
</body>
</code></pre>
<small>内嵌 PHP 代码的 script 不会压缩,当然你可以通过设置 force-compress 属性来强制压缩</small>
</section>
<section>
<h3>自动发布到 CDN</h3>
<pre><code class="hljs">
<script src="/static/js/demo.js"></script>
</code></pre>
<pre><code class="hljs">
<script src="//cbshowhot.cdn.changbaimg.com/static/js/demo.710a2da.js"></script>
</code></pre>
<div class="fragment">
<p style="font-size:60%">为标签增加 nocdn 属性则不会被发布到 CDN,例如:</p>
<pre><code class="hljs">
<script src="/static/js/demo.js" nocdn></script>
</code></pre>
</div>
</section>
<section>
<h3>其他工具</h3>
<ul>
<li>
资源生成 Data URI 并自动复制到剪贴板,例如:
<pre><code class="hljs">gulp datauri -f "/your/path/demo.png"</code></pre>
<p style="font-size:60%">下列内容会自动复制到剪贴板:</p>
<pre><code class="hljs">data:image/png;base64,iVBORw0KG......</code></pre>
</li>
<li class="fragment">
上传文件到 CDN,并生成永久唯一 URL,例如:
<pre><code class="hljs">gulp alioss -f "/your/path/demo.png"</code></pre>
<p style="font-size:60%">生成:</p>
<pre><code class="hljs">http://cbshowhot.cdn.changbaimg.com/-/19bb85c1291945b1/demo.png</code></pre>
</li>
</ul>
</section>
<section>
<h3>其他工具</h3>
<ul>
<li>
Cocos2D 资源发布到 CDN
<pre><code class="hljs">gulp resource</code></pre>
<p style="font-size:60%">生成:</p>
<pre><code class="hljs">http://cbshowhot.cdn.changbaimg.com/-/0c952f5370416f21/resource.js</code></pre>
</li>
</ul>
</section>
<section>
<h3>举个 🌰</h3>
<img style="height:12em;" data-src="images/4.png" alt="">
</section>
<section>
<h3>部署工具</h3>
<p style="text-align:left">问题:现有 svn up 的部署方式有一定的局限性</p>
<div>
<p style="text-align:left">解决:改为主动发布的形式</p>
<p style="text-align:left">主要分为四步:</p>
<ol>
<li>编译项目</li>
<li>打包上传到回归机(测试机)</li>
<li>从回归机 rsync 到线上服务器</li>
<li>如有问题回滚到上一版本</li>
</ol>
</div>
</section>
<section>
<h3>部署工具</h3>
<p>编译项目前先做文件对比</p>
<img data-src="images/6.png" alt="">
</section>
<section>
<h3>部署工具</h3>
<p>发布到回归机(测试机)</p>
<img data-src="images/7.png" alt="">
<p>如果测试有问题可以立即回滚</p>
<img data-src="images/8.png" alt="">
</section>
<section>
<h3>部署工具</h3>
<p>最后通过 rsync 同步到线上</p>
<img data-src="images/9.png" alt="">
</section>
<section>
<h3>让 SVN 分支用起来像 GIT 分支</h3>
<p>首先需要把 SVN 目录结构修改成经典分支模型</p>
<img data-src="images/5.png" alt="">
</section>
<section>
<h3>让 SVN 分支用起来像 GIT 分支</h3>
<p>然后创建类似这样的本地目录</p>
<pre>
|-- root
|
|---- project -> ./project_trunk/
|---- project_trunk
|---- project_branch_name_1
|---- project_branch_name_2
|---- project_.....
</pre>
<small>很明显,svn trunk 要 checkout 到 project_trunk 目录下</small>
</section>
<section>
<h3>让 SVN 分支用起来像 GIT 分支</h3>
<p>进入 project 目录,可以自由切换分支:</p>
<pre><code class="hljs">sh ./project/branch_switch.sh</code></pre>
<img style="height:10em" data-src="images/3.png" alt="">
</section>
<section>
<h3>让 SVN 分支用起来像 GIT 分支</h3>
<p>进入 project 目录,可以创建分支:</p>
<pre><code class="hljs">sh ./project/branch_create.sh 分支名</code></pre>
<p>可以合并分支到主干:</p>
<pre><code class="hljs">sh ./project/branch_merge.sh trunk</code></pre>
<p>也可以 checkout 其他分支:</p>
<pre><code class="hljs">sh ./project/branch_checkout.sh 分支名</code></pre>
<p style="color:#42affa">所有操作都在 project 目录下完成</p>
</section>
<section style="text-align: left;">
<h1>THE END</h1>
<p>谢谢!</p>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: false,
transition: 'slide',
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>