Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Grunt实战
Search
cssrain
July 14, 2014
Technology
120
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Grunt实战
cssrain
July 14, 2014
More Decks by cssrain
See All by cssrain
UED工作流程分享和交流
cssrain
1
540
解读HTML
cssrain
0
210
解读HTML5
cssrain
2
230
基础CSS(1)
cssrain
0
220
基础CSS(2)
cssrain
0
160
高效的CSS
cssrain
0
210
高级CSS—继承
cssrain
0
190
PhoneGap分享和交流
cssrain
0
160
PhoneGap实践
cssrain
0
110
Other Decks in Technology
See All in Technology
AIカンパニーへの転換を支えた、エンジニアの仕事の再定義
kworkdev
PRO
2
670
Snapshot Testing in Practice: Predictable and Reliable SwiftUI Views
fespinoza
0
210
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
3
360
Kiro Crewをはじめよう
kizawa2020
1
150
組み立てて楽しむ AWS Blocks 入門
kmiya84377
0
230
無理せず続ける、子育てエンジニアの学び
codmoninc
PRO
0
720
hackers_champloo_2026_tidb
makocchi
0
140
Railsで挑む大量データ永続化 〜600億件を永続化するための設計とボトルネックとの戦い〜
occhi
1
240
Claude Code本は、どのように執筆チームで書かれたか
oikon48
1
370
"優秀な誰か"の下位互換にならないために
yut0naga1_fa
1
1.8k
DWH の限界突破! AI エージェント向け爆速リアルタイムデータ基盤 ClickHouse
jozono
1
400
AIにシークレットを見せない、WSL2で安全な開発環境
yazm
0
160
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
18k
Navigating Team Friction
lara
192
16k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Into the Great Unknown - MozCon
thekraken
41
2.8k
Writing Fast Ruby
sferik
630
63k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.2k
4 Signs Your Business is Dying
shpigford
187
23k
A Tale of Four Properties
chriscoyier
163
24k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
Transcript
Grunt实战 让优化工作更轻松 UED分享 · 交流 http://cssrain.github.io
插一句 ▪ 合并文件 ▪ 压缩代码 ▪ 检查语法错误 ▪ 将Less代码转成CSS代码 ▪
… …
npm install -g grunt-cli nodejs 、 npm
node -v npm -v grunt -version
OK ! Are you ready !!!
新建 package.json
{ "name": "sh10086", "version": "0.1.0", "author": "Your Name", "devDependencies": {
"grunt": "^0.4.5", "grunt-contrib-uglify": "^0.5.0" } }
npm install
$ npm install npm http 304 https://registry.npmjs.org/whet.extend npm http GET
https://registry.npmjs.org/q npm http GET https://registry.npmjs.org/esprima npm http GET https://registry.npmjs.org/argparse npm http 304 https://registry.npmjs.org/bin-check npm http 304 https://registry.npmjs.org/download npm http 304 https://registry.npmjs.org/download npm http 304 https://registry.npmjs.org/esprima npm http 304 https://registry.npmjs.org/find-file npm http 304 https://registry.npmjs.org/argparse npm http GET https://registry.npmjs.org/decompress npm http GET https://registry.npmjs.org/each-async npm http GET https://registry.npmjs.org/get-urls npm http GET https://registry.npmjs.org/through2 npm http GET https://registry.npmjs.org/request npm http GET https://registry.npmjs.org/executable npm http 304 https://registry.npmjs.org/q npm http 304 https://registry.npmjs.org/request … …
新建Gruntfile.js
//"wrapper"函数(包装函数) module.exports = function(grunt){ // 项目和任务配置 grunt.initConfig({ uglify: { build:
{ src: 'src/my-project.js', dest: 'build/out.min.js' } } }); // 加载的Grunt插件和任务 uglify grunt.loadNpmTasks('grunt-contrib-uglify'); // 默认任务,自定义任务 grunt.registerTask('default', ['uglify']); grunt.registerTask('test', ['uglify']); }
grunt
哦也,压缩成功!
让暴风雨来的更猛烈些吧 css和js的分别合并 css压缩 js压缩 js代码检测 图片压缩 css和js代码修改监听
{ "name": "sh10086", "version": "0.1.0", "author": "Your Name", "devDependencies": {
"grunt": "^0.4.5", "grunt-contrib-uglify": "^0.5.0" } } 新建 package.json
npm install grunt-contrib-jshint --save-dev npm install grunt-contrib-concat --save-dev npm install
grunt-contrib-uglify --save-dev npm install grunt-contrib-imagemin --save-dev npm install grunt-contrib-watch --save-dev
{ "name": "sh10086", "version": "0.1.0", "author": "Your Name", "devDependencies": {
"grunt": "^0.4.5", "grunt-contrib-uglify": "^0.5.0" } } { "name": "sh10086", "version": "0.1.0", "author": "Your Name", "devDependencies": { "grunt": "^0.4.5", "grunt-contrib-uglify": "^0.5.0", "grunt-contrib-concat": "^0.4.0", "grunt-contrib-cssmin": "^0.10.0", "grunt-contrib-imagemin": "^0.7.1", "grunt-contrib-jshint": "*", "grunt-contrib-watch": "^0.6.1" } }
//"wrapper"函数(包装函数) module.exports = function(grunt){ // 项目和任务配置 grunt.initConfig({ cssmin: { minify:
{ expand: true, //如果设为true,就表示下面文件名的占位符(即*号)都要扩展成具体的文件名。 cwd: 'res/theme/', //需要处理的文件(input)所在的目录。 src: ['*.css', 'alice/*.css', '!*.min.css', '!alice/*.min.css'], //表示需要处理的文件。可以使用通配符。 dest: 'res/theme/', //表示处理后的文件名或所在目录。 ext: '.min.css' //表示处理后的文件后缀名。 }, combine: { files: { 'res/theme/out.min.css': ['res/theme/10086.min.css', 'res/theme/qijc.min.css'] } } } }); // 加载的Grunt插件和任务 cssmin grunt.loadNpmTasks('grunt-contrib-cssmin'); // 默认任务,自定义任务 grunt.registerTask('default', [‘cssmin']); grunt.registerTask('test', [‘cssmin']); } 新建Gruntfile.js
module.exports = function(grunt){ // 详情请看项目中的Gruntfile.js } 完整的Gruntfile.js
$ grunt Running "jshint:files" (jshint) task >> 4 files lint
free. Running "cssmin:minify" (cssmin) task File res/theme/10086.min.css created: 5.82 kB → 5.21 kB File res/theme/qijc.min.css created: 8.4 kB → 5.86 kB File res/theme/alice/alice.min.css created: 132.46 kB → 98.9 kB Running "cssmin:combine" (cssmin) task File res/theme/out.min.css created: 11.07 kB → 11.07 kB Running "concat:js" (concat) task File res/common/out.js created. Running "uglify:target" (uglify) task File res/common/out.min.js created: 2.66 kB → 856 B Running "imagemin:dynamic" (imagemin) task ✔ images/4gzq.jpg (saved 19.59 kB - 70%) ✔ images/banner1.jpg (saved 913 B - 1%) … … Minified 24 images (saved 26.7 kB) Done, without errors.
不是写程序,而是写配置
Gulp.js
500 520 540 560 580 600 620 文件大小(KB) 文件大小优化 优化前
优化后 17 17.5 18 18.5 19 19.5 20 20.5 连接数(个) HTTP连接数优化 优化前 优化后
Yeoman Yo 脚手架工具 Bower 包管理器 Grunt 构建工具
UED分享 · 交流 http://cssrain.github.io Thank you