Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Grunt实战
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
cssrain
July 14, 2014
Technology
110
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
480
解读HTML
cssrain
0
150
解读HTML5
cssrain
2
180
基础CSS(1)
cssrain
0
160
基础CSS(2)
cssrain
0
120
高效的CSS
cssrain
0
160
高级CSS—继承
cssrain
0
140
PhoneGap分享和交流
cssrain
0
110
PhoneGap实践
cssrain
0
87
Other Decks in Technology
See All in Technology
ChatworkとBPaaS 異なる特性で学んだAI機能開発の ベストプラクティス
kubell_hr
2
2.8k
ITエンジニアを取り巻く環境とキャリアパス / A career path for Japanese IT engineers
takatama
4
1.8k
Platform engineering for developers, architects & the rest of us (AI agents)
danielbryantuk
0
180
AI駆動開発が変える、大規模開発の前提 ーHuman in the Loop から Human on the Loop へ / AIE2026
visional_engineering_and_design
18
8.8k
AI活用を推進するために ファインディが下した、一つの小さな決断
starfish719
0
250
サプライチェーンセキュリティの空白地帯 - 信頼できる”依存性”の未来を考える
rung
PRO
2
700
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
1.9k
GoとSIMDとWasmの今。
askua
3
510
SIer20年! 培ったスキルがスタートアップで輝く時
shucho0103
0
440
OCI Oracle AI Database Services新機能アップデート(2026/03-2026/05)
oracle4engineer
PRO
0
230
Amazon Bedrock AgentCore ワークショップ JAWS UG TOHOKU / amazon-bedrock-agentcore-workshop-jawsug-tohoku-2026
gawa
8
310
美味しいスイスチーズを作ろう🧀🐭
taigamikami
1
240
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.9k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
860
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
44k
30 Presentation Tips
portentint
PRO
1
320
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
The Cost Of JavaScript in 2023
addyosmani
55
10k
Test your architecture with Archunit
thirion
1
2.3k
Agile that works and the tools we love
rasmusluckow
331
21k
Into the Great Unknown - MozCon
thekraken
41
2.5k
Building an army of robots
kneath
306
46k
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