【问题标题】:Grunt plugins not found using load-grunt-config使用 load-grunt-config 找不到 Grunt 插件
【发布时间】:2014-11-22 13:54:55
【问题描述】:

我已将我的 grunt 插件拆分为它们自己的文件,并使用 load-grunt-config (https://github.com/firstandthird/load-grunt-config) 来调用它们:

module.exports = function (grunt) {

  'use strict';

  require('load-grunt-config')(grunt);
}; 

我有 sass、autoprefixer、cssmin 和 watch 任务,但我也在使用 Browsersync 和 px-to-rem 这两个插件返回:

Warning: Task "remify" not found. Use --force to continue.

Warning: Task "browsersync" not found. Use --force to continue.

单独调用或作为更大任务的一部分调用时。

我已经遵循了这两个插件的separate.js 文件的语法,所以我很茫然。比如运行 grunt 时调用的 remify.js 文件是这样写的

module.exports = {
  dist: {
    options: {
      base: 16,
      fallback: true,
      fallback_existing_rem: true,
      ignore: []
    },
    files: {
      'css/style.css': 'css/style.css'
    }
  }
};

有什么想法会出错吗?

我还设置了示例代码的要点,包括 package.json 和 aliases.yml

https://gist.github.com/sturobson/f88258fd010e901e24d9

【问题讨论】:

    标签: javascript node.js gruntjs browser-sync


    【解决方案1】:

    你必须准确地称呼grunt插件。所以我有remify 的地方应该使用px_to_rem,而我有browsersync 的地方应该有browserSync

    我真傻。

    【讨论】:

      【解决方案2】:

      您可以将第二个参数传递给load-grunt-config 以提供一些选项,您还可以定义一些可供load-grunt-tasks 在内部使用的模式。

      如果您不传递第二个参数,它将使用load-grunt-tasks 的默认模式grunt-*

      因此,如果您想加载所有 devDependencies 而不单独定义它们,请这样做:

      require('load-grunt-config')(grunt, {
          loadGruntTasks: {
              pattern: '*',
              scope: 'devDependencies'
          }
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-06-15
        • 2015-03-30
        • 2015-04-07
        • 2016-04-11
        • 1970-01-01
        • 2014-08-15
        • 1970-01-01
        相关资源
        最近更新 更多