跳到主要內容

發表文章

目前顯示的是 1月, 2014的文章

GRUNT SMARTER AND AUTOMATE - Grunt watch

We have do something smarter and automate with grunt after JS optimization. Let's install "grunt-contrib-watch" that run predefined tasks whenever watched file patterns are added, changed or deleted. How to install ? 1. Run " npm install grunt - contrib - watch --save-dev"  in ur project location. 2. Add " grunt . loadNpmTasks ( 'grunt-contrib-watch' );" in Gruntfile.js  loated in ur project location. Gruntfile.js - The sample use Closure complier to optimize JS file.  »see more module.exports = function(grunt) { grunt.initConfig({ file: { min: { dest: 'js/opt/min.js', src: [ 'js/jquery.tools/overlay/overlay.js', 'js/jquery.tools/scrollable/scrollable.js', ] } }, 'closure-compiler': { min: { closurePath:'/Library/closure/', ...

Grunt (Dynamic build) + Closure (JS compiler)

- Grunt is a task-based command line build tool for JavaScript project. - Closure Compiler is a tool for making JavaScript download and run faster. Why? 專案開發時經常有過多的JS需要管理, 很多不必要的空白, 沒用到程式和變數都可以移除, 甚至更進一步做命名的 簡化, 這些可以透過google closure做到, 有三種優化模式可選擇WHITESPACE_ONLY,SIMPLE_OPTIMIZATIONS, ADVANCED_OPTIMIZATIONS, 但要如何一次優化多筆JS呢?就可以透過Grunt來做到 How to install? 1.nodejs 安裝, 就有npm可以使用 ➺See here Node包管理器簡稱npm。它是一個Node.js的包管理器,運行在命令行下,用於管理應用的依賴。 按照作者的定義,npm不是“Node Package Manager”的縮寫。 從Node.js0.6版本開始,npm被自動附帶在安裝包中。 2.grunt-cli install  http://gruntjs.com/getting-started  "npm install -g grunt-cli" 3.Project location run "npm install grunt --save-dev" 4.Project location run "npm install grunt-closure-compiler" 5.Create "Gruntfile.js" in project location. --->請見下方 6.Download closure compiler.jar  https://developers.google.com/closure/compiler/ ➺Lastest compiler.jar download here , 若compiler發生Warning: Command failed: ...