SlideShare ist ein Scribd-Unternehmen logo
1 von 18
Downloaden Sie, um offline zu lesen
GruntJS
2015.05.15 By Ian.
JavaScript Build System
 Npm
 Grunt
 Gulp
The Good Parts
 Grunt有一個完善的社群,即使是在Windows上
 它不僅僅應用在Node社群
 它簡單易學,你可以隨便安裝插件並配置它們
 你不需要多先進的理念,也不需要任何經驗
Installing the CLI
 Grunt's command line interface
 npm install -g grunt-cli
 The job of the Grunt CLI is simple: run the version of Grunt
which has been installed next to a Gruntfile.
Preparing a new Grunt project
 package.json: This file is used by npm to store metadata
for projects published as npm modules. You will list grunt
and the Grunt plugins your project needs as
devDependencies in this file.
 Gruntfile: This file is named Gruntfile.js or Gruntfile.coffee
and is used to configure or define tasks and load Grunt
plugins.
Installing Grunt and gruntplugins
 Install the latest version of Grunt in your project folder,
adding it to your devDependencies:
 npm install grunt --save-dev
 Install Task module
 npm install grunt-contrib-jshint --save-dev
The Gruntfile
A Gruntfile is comprised of the following parts:
 The "wrapper" function
 Project and task configuration
 Loading Grunt plugins and tasks
 Custom tasks
An example Gruntfile
Loading Grunt plugins and tasks
 Load the plugin that provides the "uglify" task.
 grunt.loadNpmTasks('grunt-contrib-uglify');
Custom tasks
 // Default task(s).
 grunt.registerTask('default', ['uglify']);
 // A very basic default task.
 grunt.registerTask('default', 'Log some stuff.', function() {
 grunt.log.write('Logging some stuff...').ok();
 });
Plugin
 http://gruntjs.com/plugins
 grunt-contrib-clean: 用於清理指定文件(夾),一般是構建
之前或之後進行
 grunt-contrib-coffee: 將CoffeeScript編譯為JavaScript
 grunt-contrib-compass: 使用Compass工具生成CSS文件
 grunt-contrib-concat: 連接文件,減少HTTP請求
 grunt-contrib-copy: 複製文件(夾)
Plugin
 grunt-contrib-jshint:
 grunt-contrib-watch: 監視文件,一旦更改就會重新運行指定
的任務,例如使http服務器重新加載源文件
 grunt-contrib-ugligy: 壓縮JS文件,提高運行時性能
 grunt-contrib-less  grunt-contrib-sass  grunt-contrib-
compass
 grunt-ts
The Bad Parts
 缺點1.:複雜的編繹過程,它可能會變得過於冗長。當開發一段
時間以後,它往往很難將編繹過程作為一個整體。一旦你編繹
流程任務到達兩位數,幾乎可以保證,你會發現自己不得不在
多個目標(Targets)中跑同一個Task
 缺點2.需要為每個任務(或者每個編繹流)編寫一份獨立的配置
文件
 缺點3.Grunt的最大缺點之一就是它的I/O限制。這意味著大多
數Grunt的任務將從硬碟中讀取,再寫入到硬碟。如果你的多個
任務需要操作同一個文件,那麼該文件很有可能被從硬碟中多
次讀取。
將npm視為構建工具
 {
 "scripts": {
 "test": "jshint . --exclude node_modules"
 },
 "devDependencies": {
 "jshint": "^2.5.1"
 }
 }
 npm run test
npm
 {
 "scripts": {
 "lint": "jshint . --exclude node_modules",
 "unit": "tape test/*",
 "test": "npm run lint && npm run unit"
 },
 "devDependencies": {
 "jshint": "^2.5.1",
 "tape": "~2.10.2"
 }
 }
With Bash cmd
 {
 "scripts": {
 "build-js": "cp -r src/js/vendor bin/js",
 "build-css": "stylus src/css/all.styl -o bin/css",
 "build": "npm run build-js & npm run build-css"
 },
 "devDependencies": {
 "stylus": "^0.45.0"
 }
 }
 可以利用NPM的所有優勢,它有數以萬計的 Module 可以選擇。
除了NPM,你不需要任何額外的命令行工具(CLI)或文件,你只
需要在package.json添加依賴關係。
 也許NPM的最大的缺點是,在Windows環境中的應用可能沒那
麼好。
Reference
 http://modernweb.com/2014/08/04/choose-grunt-gulp-
npm/?utm_source=ourjs.com
 http://gruntjs.com/
 http://gruntjs.com/plugins

Weitere ähnliche Inhalte

Was ist angesagt?

開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽Will Huang
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub維佋 唐
 
SQL Server 資料庫版本控管
SQL Server 資料庫版本控管SQL Server 資料庫版本控管
SQL Server 資料庫版本控管Will Huang
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹Max Ma
 
Docker 淺入淺出
Docker 淺入淺出Docker 淺入淺出
Docker 淺入淺出Miles Chou
 
Node.js從無到有 基本課程
Node.js從無到有 基本課程Node.js從無到有 基本課程
Node.js從無到有 基本課程Simon Su
 
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式Bo-Yi Wu
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to gitBo-Yi Wu
 
Introduction to Golang final
Introduction to Golang final Introduction to Golang final
Introduction to Golang final Paul Chao
 
容器式基礎架構介紹
容器式基礎架構介紹容器式基礎架構介紹
容器式基礎架構介紹Philip Zheng
 
企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養Philip Zheng
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學hydai
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧Chu-Siang Lai
 
快快樂樂學 Angular 2 開發框架
快快樂樂學 Angular 2 開發框架快快樂樂學 Angular 2 開發框架
快快樂樂學 Angular 2 開發框架Will Huang
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略Lucien Lee
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIChu-Siang Lai
 
React.js what do you really mean?
React.js what do you really mean?React.js what do you really mean?
React.js what do you really mean?昱安 周
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學littlebtc
 

Was ist angesagt? (20)

開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽開發人員不可不知的 Windows Container 容器技術預覽
開發人員不可不知的 Windows Container 容器技術預覽
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub
 
SQL Server 資料庫版本控管
SQL Server 資料庫版本控管SQL Server 資料庫版本控管
SQL Server 資料庫版本控管
 
Git基礎介紹
Git基礎介紹Git基礎介紹
Git基礎介紹
 
Docker 淺入淺出
Docker 淺入淺出Docker 淺入淺出
Docker 淺入淺出
 
Node.js從無到有 基本課程
Node.js從無到有 基本課程Node.js從無到有 基本課程
Node.js從無到有 基本課程
 
Docker應用
Docker應用Docker應用
Docker應用
 
用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式用 Docker 改善團隊合作模式
用 Docker 改善團隊合作模式
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Docker Build
Docker BuildDocker Build
Docker Build
 
Introduction to Golang final
Introduction to Golang final Introduction to Golang final
Introduction to Golang final
 
容器式基礎架構介紹
容器式基礎架構介紹容器式基礎架構介紹
容器式基礎架構介紹
 
企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養企業導入容器經驗分享與開源技能培養
企業導入容器經驗分享與開源技能培養
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學
 
前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧前端工程師一定要知道的 Docker 虛擬化容器技巧
前端工程師一定要知道的 Docker 虛擬化容器技巧
 
快快樂樂學 Angular 2 開發框架
快快樂樂學 Angular 2 開發框架快快樂樂學 Angular 2 開發框架
快快樂樂學 Angular 2 開發框架
 
初心者 Git 上手攻略
初心者 Git 上手攻略初心者 Git 上手攻略
初心者 Git 上手攻略
 
Continuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CIContinuous Delivery with Ansible x GitLab CI
Continuous Delivery with Ansible x GitLab CI
 
React.js what do you really mean?
React.js what do you really mean?React.js what do you really mean?
React.js what do you really mean?
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 

Ähnlich wie Ian 20150515 grunt

Npm 套件管理 & 常用開發工具介紹
Npm 套件管理 & 常用開發工具介紹Npm 套件管理 & 常用開發工具介紹
Npm 套件管理 & 常用開發工具介紹wantingj
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Yiwei Ma
 
使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理Jason Zheng
 
GNU Build System
GNU Build SystemGNU Build System
GNU Build Systemimacat .
 
Android系统移植技术详解
Android系统移植技术详解Android系统移植技术详解
Android系统移植技术详解zzc89522
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuMarsZ Chen
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡cachowu
 
Ruby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacRuby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacMarsZ Chen
 
5, system admin
5, system admin5, system admin
5, system adminted-xu
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linuxYiwei Ma
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结Yiwei Ma
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用Philip Zheng
 
Android -汇博
Android -汇博Android -汇博
Android -汇博dlqingxi
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版Jie Bao
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on praticeKenny (netman)
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战icy leaf
 
Eclipse4.0+cdt+cygwin+gdb开发环境搭建
Eclipse4.0+cdt+cygwin+gdb开发环境搭建Eclipse4.0+cdt+cygwin+gdb开发环境搭建
Eclipse4.0+cdt+cygwin+gdb开发环境搭建_MoYang
 
Clojure cnclojure-meetup
Clojure cnclojure-meetupClojure cnclojure-meetup
Clojure cnclojure-meetupsunng87
 
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...Laird Cheng
 

Ähnlich wie Ian 20150515 grunt (20)

Npm 套件管理 & 常用開發工具介紹
Npm 套件管理 & 常用開發工具介紹Npm 套件管理 & 常用開發工具介紹
Npm 套件管理 & 常用開發工具介紹
 
Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)
 
Build Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratchBuild Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratch
 
使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理
 
GNU Build System
GNU Build SystemGNU Build System
GNU Build System
 
Android系统移植技术详解
Android系统移植技术详解Android系统移植技术详解
Android系统移植技术详解
 
Ruby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for UbuntuRuby on Rails 開發環境建置 for Ubuntu
Ruby on Rails 開發環境建置 for Ubuntu
 
使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡使用Nginx轻松实现开源负载均衡
使用Nginx轻松实现开源负载均衡
 
Ruby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for MacRuby on Rails 開發環境建置 for Mac
Ruby on Rails 開發環境建置 for Mac
 
5, system admin
5, system admin5, system admin
5, system admin
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linux
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
 
Android -汇博
Android -汇博Android -汇博
Android -汇博
 
unix toolbox 中文版
unix toolbox 中文版unix toolbox 中文版
unix toolbox 中文版
 
Linux network monitoring hands-on pratice
Linux network monitoring hands-on praticeLinux network monitoring hands-on pratice
Linux network monitoring hands-on pratice
 
Git 入门实战
Git 入门实战Git 入门实战
Git 入门实战
 
Eclipse4.0+cdt+cygwin+gdb开发环境搭建
Eclipse4.0+cdt+cygwin+gdb开发环境搭建Eclipse4.0+cdt+cygwin+gdb开发环境搭建
Eclipse4.0+cdt+cygwin+gdb开发环境搭建
 
Clojure cnclojure-meetup
Clojure cnclojure-meetupClojure cnclojure-meetup
Clojure cnclojure-meetup
 
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
 

Mehr von LearningTech

Mehr von LearningTech (20)

vim
vimvim
vim
 
PostCss
PostCssPostCss
PostCss
 
ReactJs
ReactJsReactJs
ReactJs
 
Docker
DockerDocker
Docker
 
Semantic ui
Semantic uiSemantic ui
Semantic ui
 
node.js errors
node.js errorsnode.js errors
node.js errors
 
Process control nodejs
Process control nodejsProcess control nodejs
Process control nodejs
 
Expression tree
Expression treeExpression tree
Expression tree
 
SQL 效能調校
SQL 效能調校SQL 效能調校
SQL 效能調校
 
flexbox report
flexbox reportflexbox report
flexbox report
 
Reflection & activator
Reflection & activatorReflection & activator
Reflection & activator
 
Peggy markdown
Peggy markdownPeggy markdown
Peggy markdown
 
Node child process
Node child processNode child process
Node child process
 
20160415ken.lee
20160415ken.lee20160415ken.lee
20160415ken.lee
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
Expression tree
Expression treeExpression tree
Expression tree
 
Vic weekly learning_20160325
Vic weekly learning_20160325Vic weekly learning_20160325
Vic weekly learning_20160325
 
D3js learning tips
D3js learning tipsD3js learning tips
D3js learning tips
 
git command
git commandgit command
git command
 
Asp.net MVC DI
Asp.net MVC DIAsp.net MVC DI
Asp.net MVC DI
 

Ian 20150515 grunt

  • 2. JavaScript Build System  Npm  Grunt  Gulp
  • 3. The Good Parts  Grunt有一個完善的社群,即使是在Windows上  它不僅僅應用在Node社群  它簡單易學,你可以隨便安裝插件並配置它們  你不需要多先進的理念,也不需要任何經驗
  • 4. Installing the CLI  Grunt's command line interface  npm install -g grunt-cli  The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile.
  • 5. Preparing a new Grunt project  package.json: This file is used by npm to store metadata for projects published as npm modules. You will list grunt and the Grunt plugins your project needs as devDependencies in this file.  Gruntfile: This file is named Gruntfile.js or Gruntfile.coffee and is used to configure or define tasks and load Grunt plugins.
  • 6. Installing Grunt and gruntplugins  Install the latest version of Grunt in your project folder, adding it to your devDependencies:  npm install grunt --save-dev  Install Task module  npm install grunt-contrib-jshint --save-dev
  • 7. The Gruntfile A Gruntfile is comprised of the following parts:  The "wrapper" function  Project and task configuration  Loading Grunt plugins and tasks  Custom tasks
  • 9. Loading Grunt plugins and tasks  Load the plugin that provides the "uglify" task.  grunt.loadNpmTasks('grunt-contrib-uglify');
  • 10. Custom tasks  // Default task(s).  grunt.registerTask('default', ['uglify']);  // A very basic default task.  grunt.registerTask('default', 'Log some stuff.', function() {  grunt.log.write('Logging some stuff...').ok();  });
  • 11. Plugin  http://gruntjs.com/plugins  grunt-contrib-clean: 用於清理指定文件(夾),一般是構建 之前或之後進行  grunt-contrib-coffee: 將CoffeeScript編譯為JavaScript  grunt-contrib-compass: 使用Compass工具生成CSS文件  grunt-contrib-concat: 連接文件,減少HTTP請求  grunt-contrib-copy: 複製文件(夾)
  • 12. Plugin  grunt-contrib-jshint:  grunt-contrib-watch: 監視文件,一旦更改就會重新運行指定 的任務,例如使http服務器重新加載源文件  grunt-contrib-ugligy: 壓縮JS文件,提高運行時性能  grunt-contrib-less grunt-contrib-sass grunt-contrib- compass  grunt-ts
  • 13. The Bad Parts  缺點1.:複雜的編繹過程,它可能會變得過於冗長。當開發一段 時間以後,它往往很難將編繹過程作為一個整體。一旦你編繹 流程任務到達兩位數,幾乎可以保證,你會發現自己不得不在 多個目標(Targets)中跑同一個Task  缺點2.需要為每個任務(或者每個編繹流)編寫一份獨立的配置 文件  缺點3.Grunt的最大缺點之一就是它的I/O限制。這意味著大多 數Grunt的任務將從硬碟中讀取,再寫入到硬碟。如果你的多個 任務需要操作同一個文件,那麼該文件很有可能被從硬碟中多 次讀取。
  • 14. 將npm視為構建工具  {  "scripts": {  "test": "jshint . --exclude node_modules"  },  "devDependencies": {  "jshint": "^2.5.1"  }  }  npm run test
  • 15. npm  {  "scripts": {  "lint": "jshint . --exclude node_modules",  "unit": "tape test/*",  "test": "npm run lint && npm run unit"  },  "devDependencies": {  "jshint": "^2.5.1",  "tape": "~2.10.2"  }  }
  • 16. With Bash cmd  {  "scripts": {  "build-js": "cp -r src/js/vendor bin/js",  "build-css": "stylus src/css/all.styl -o bin/css",  "build": "npm run build-js & npm run build-css"  },  "devDependencies": {  "stylus": "^0.45.0"  }  }
  • 17.  可以利用NPM的所有優勢,它有數以萬計的 Module 可以選擇。 除了NPM,你不需要任何額外的命令行工具(CLI)或文件,你只 需要在package.json添加依賴關係。  也許NPM的最大的缺點是,在Windows環境中的應用可能沒那 麼好。

Hinweis der Redaktion

  1. his allows multiple versions of Grunt to be installed on the same machine simultaneously.
  2. Install project dependencies with npm install. Run Grunt with grunt.