2016-03-02 47 views
0

在我的設置中,我使用grunt-load-config將我的grunt文件拆分爲單獨的文件。 這意味着我爲每個想要使用的grunt插件都有一個文件。如何在使用grunt-load-config的Grunt設置中使用組合插件

gruntfile.js看起來是這樣的:

module.exports = function(grunt) { 
    var path = require('path'); 

    // measures the time each task takes 
    require('time-grunt')(grunt); 

    // load grunt config 
    require('load-grunt-config')(grunt, { 
     jitGrunt: true, 
     configPath: path.join(process.cwd(), 'Interface/grunttasks') 
    }); 
}; 

和我Interface/grunttasks/assemble.js組裝的設置是這樣

module.exports = { 

    options: { 
     flatten: true, 
     partials: ['<%= package.html %>/_partials/*.html'], 
     layout: '<%= package.html %>/_layouts/main.html' 
    }, 

    pages: { 
     src: ['<%= package.pages %>/**/*.html', 
     dest: '<%= package.prototype %>' 
    } 

}; 

這工作完全如預期,但現在我想用一組組裝的助手。但我不確定我應該如何將它們添加到我的咕嚕安裝程序中,以便組裝(並反過來把手)可以使用它們。

我已經看過了prettify幫手,他們的安裝說明很簡單,就是「以下內容添加到您的應用程序」

var helpers = require('prettify'); 

然後,我應該只能夠配置添加到我的組裝塊在我的grunt文件,像這樣

grunt.initConfig({ 
    assemble: { 
     options: { 
      prettify: { 
       mode: 'js', // 'html' is defined by default 
       condense: true, 
       padcomments: true, 
       indent: 4 
      } 
     }, 
     ... 
     } 
}); 

但我似乎無法得到插件正確註冊。我猜是因爲我分裂了我的咕嚕文件?

任何人都可以解釋如何添加組裝插件/助手在這個咕嚕設置?

回答

0

看起來應該在該存儲庫上更新自述文件。

名字既然現在handlebars-helper-prettify你應該能夠將其添加爲一個開發依賴性:

$ npm i handlebars-helper-prettify -D 

然後包括它在你的組合配置helpers選項:

grunt.initConfig({ 
    assemble: { 
     options: { 
      helpers: ['handlebars-helpers-prettify'], 
      prettify: { 
       mode: 'js', // 'html' is defined by default 
       condense: true, 
       padcomments: true, 
       indent: 4 
      } 
     }, 
     ... 
     } 
}); 

希望這幫助。隨意打開有關自述文件的問題或公關,以便更新。

+0

這個伎倆。 在閱讀文檔時,添加插件到名爲helpers的數組中的事實並不十分清楚。事實上,插件實際上被稱爲別的文檔狀態也不是很容易弄清楚;) – SuneRadich

+0

我同意文檔需要更新,但這不是一個插件,它是一個幫手,這就是爲什麼它被添加通過'helpers'屬性。在最新版本的彙編中,瞭解helpers和插件之間的區別更容易。 – doowb

相關問題