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
520
解读HTML
cssrain
0
190
解读HTML5
cssrain
2
210
基础CSS(1)
cssrain
0
200
基础CSS(2)
cssrain
0
150
高效的CSS
cssrain
0
200
高级CSS—继承
cssrain
0
170
PhoneGap分享和交流
cssrain
0
150
PhoneGap实践
cssrain
0
99
Other Decks in Technology
See All in Technology
PQC移行の今 -- IETF からみた現在地
satokan
3
190
絵ではじめるKubernetesセキュリティ
aoi1
5
710
データ_AIの事業の勝敗をわけるもの
nek0128
1
480
Oracle Cloud Infrastructure(OCI):Onboarding Session(はじめてのOCI/Oracle Supportご利⽤ガイド)
oracle4engineer
PRO
2
20k
AIエージェントを安全で速い現場監督にする:Jev・Obsidian・メタハーネス
x5gtrn
PRO
0
100
10年欲しかった音楽管理アプリを、AIと一緒に作りはじめた
judau
1
110
Lambda MicroVMsは常駐サーバーの代わりに なるか? Kiro Crew を動かして検証してみた / Kiro Crew on Lambda MicroVMs
k_adachi_01
2
200
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
技術的負債から考える、AI時代のエンジニアリング投資 — ビズリーチの技術的負債と向き合った経験から、変更し続けられるソフトウェアを考える/ technical-debt-con2026
visional_engineering_and_design
4
3.7k
今話題のAI「Jev」って何? 宇宙最速で学ぶ会
minorun365
PRO
32
21k
AI感のないAWS構成図をAIエージェントに描かせたい!
sagochiko
1
350
Von-Neumann Machines, Dreams & The Futures of IT
ufried
0
130
Featured
See All Featured
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
730
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
280
A Tale of Four Properties
chriscoyier
163
24k
The SEO Collaboration Effect
kristinabergwall1
1
570
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
340
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
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