Gruntfile 的設定可以直接從下面例子來看。
1 | module.exports = function(grunt) { |
設定大概會分幾個部份,會有 Task 與 Target 的設定,有 npm 套件的載入,以及 Task 的註冊。
以這例子來說,這邊設定了 jshint task,這個 task 會用 jshint 分析指定的 javascript 的程式。
許多套件都會牽扯到檔案的設定,像是上面例子 jshint 要分析的檔案就是要設定的。Grunt 對於檔案設定提供了三種不同的設定方式,分別是 Compact Format、Files Object Format、Files Array Format。
Compact Format 設定方式如下,可指定一組 source 與 destination 檔案。
1 | grunt.initConfig({ |
Files Object Format 設定方式如下,可指定多組 source 與 destination 檔案,:
前面是 destination,後面是 source。
1 | grunt.initConfig({ |
Files Array Format 設定方式如下,除了可指定多組 source 與 destination 檔案外,還能附加額外的屬性。
1 | grunt.initConfig({ |