【问题标题】:How can I use assemble plugins in a Grunt setup using grunt-load-config如何使用 grunt-load-config 在 Grunt 设置中使用 assemble 插件
【发布时间】:2016-06-15 00:19:24
【问题描述】:

在我的设置中,我使用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 中的组装设置看起来像这样

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 设置中,以便组装(以及车把)可以使用它们。

我查看了 prettify 帮助程序,他们的安装说明只是“将以下内容添加到您的应用程序”

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 设置中添加组装插件/帮助程序?

【问题讨论】:

    标签: gruntjs assemble


    【解决方案1】:

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

    由于名称现在是 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,以便对其进行更新。

    【讨论】:

    • 这成功了。在阅读文档时,您在名为 helpers 的数组中添加插件这一事实并不十分清楚。事实上,该插件实际上被称为文档状态之外的其他东西这一事实也不太容易弄清楚;)
    • 我同意文档需要更新,但这不是一个插件,它是一个助手,这就是它通过helpers 属性添加的原因。在最新版本的 assemble 中更容易了解帮助程序和插件之间的区别。
    猜你喜欢
    • 1970-01-01
    • 2014-04-12
    • 1970-01-01
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 2015-03-30
    • 2016-04-23
    相关资源
    最近更新 更多