如何使用 grunt-load-config 在 Grunt 设置中使用 assemble 插件

How can I use assemble plugins in a Grunt setup using grunt-load-config

在我的设置中,我使用 grunt-load-config 将我的 gruntfile 分成单独的文件。 这意味着我要使用的每个 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 中的 assemble 设置如下所示

module.exports = {

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

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

};

这完全符合预期,但现在我想使用一组 assemble 助手。但我不确定我应该如何将它们添加到我的 grunt 设置中,以便 assemble(以及车把)可以使用它们。

我看过 prettify 助手,他们的安装说明很简单 'add the following to your application'

var helpers = require('prettify');

然后我应该能够将配置添加到我的 gruntfile 中的 assemble 块,就像这样

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

但我似乎无法正确注册该插件。我猜是因为我拆分了我的 grunt 文件?

有人能解释一下如何在这个 grunt 设置中添加 assemble plugins/helpers 吗?

看起来应该在该存储库上更新自述文件。

由于名称现在是 handlebars-helper-prettify,您应该可以将其添加为开发依赖项:

$ npm i handlebars-helper-prettify -D

然后将其包含在 assemble 配置的 helpers 选项中:

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

希望这对您有所帮助。请随意打开关于自述文件的问题或 PR,以便对其进行更新。