Gruntjs 如何使用Grunt load config在Grunt设置中使用汇编插件

Gruntjs 如何使用Grunt load config在Grunt设置中使用汇编插件,gruntjs,assemble,Gruntjs,Assemble,在我的设置中,我已使用将GrunFile拆分为单独的文件。 这意味着我要使用的每个grunt插件都有一个文件 我的grunfile.js如下所示: module.exports = function(grunt) { var path = require('path'); // measures the time each task takes require('time-grunt')(grunt); // load grunt config req

在我的设置中,我已使用将GrunFile拆分为单独的文件。 这意味着我要使用的每个grunt插件都有一个文件

我的
grunfile.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')
    });
};
我在
界面/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 %>'
    }

};
grunt.initConfig({
    assemble: {
        options: {
            prettify: {
                mode: 'js',  // 'html' is defined by default
                condense: true,
                padcomments: true,
                indent: 4
            }
        },
        ...
      }
});
然后我应该能够将配置添加到GrunFile中的汇编块中,如下所示

module.exports = {

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

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

};
grunt.initConfig({
    assemble: {
        options: {
            prettify: {
                mode: 'js',  // 'html' is defined by default
                condense: true,
                padcomments: true,
                indent: 4
            }
        },
        ...
      }
});
但是我似乎无法正确注册插件。我猜是因为我把我的grunt文件分开了


有人能解释如何在这个grunt设置中添加汇编插件/助手吗?

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

由于名称现在是
handlebar helper prettify
,您应该能够将其添加为开发人员依赖项:

$ npm i handlebars-helper-prettify -D
然后将其包括在组装配置中的
帮助程序
选项中:

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

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

这就成功了。阅读文档时,在名为helpers的数组中添加插件的事实并不十分清楚。事实上,插件实际上被称为文档状态之外的其他东西,这一点也不容易理解;)我同意文档需要更新,但这不是一个插件,而是一个助手,这就是为什么它是通过
helpers
属性添加的。在最新版本的Assembly中,了解帮助程序和插件之间的差异更容易。