【问题标题】:grunt required config property missinggrunt 所需的配置属性丢失
【发布时间】:2016-08-19 06:55:54
【问题描述】:

设置一个新项目,其中包含多个我想从任务文件加载的 grunt 任务。

在运行我的第一个任务“core”时,它应该为站点构建核心 css,我遇到了一个似乎无法解决的错误。一直在做一些谷歌搜索,但没有找到这个具体问题。具有相同错误消息的任何问题通常是 OP 的拼写错误或花括号放错位置的结果。不确定这里是不是这样,但也许其他人看到了我显然没有看到的东西。

Gruntfile.js

module.exports = function(grunt) {

    grunt.initConfig({
        pkg: require('./package.json')
    });

    grunt.loadTasks('grunt-tasks');

};

grunt-tasks/grunt-core.js

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-sass');
    grunt.config('core', {
        sass : {
            options : {
                sourceMap : true,
                includePaths : 'node_modules/bootstrap-sass/assets/stylesheets'
            },
            dist : {
                files : {
                    'main.css' : 'main.scss'
                }
            }
        }
    });
    grunt.registerTask('core', ['sass:dist']);
};

错误:

$ grunt core
Running "sass:dist" (sass) task
Verifying property sass.dist exists in config...ERROR
>> Unable to process task.
Warning: Required config property "sass.dist" missing. Use --force to continue.

Aborted due to warnings.

我尝试了几种不同的方法。如果我将 registerTask 更改为:

grunt.registerTask('core', ['sass']);

我收到此错误:

$ grunt core
>> No "sass" targets found.
Warning: Task "sass" failed. Use --force to continue.

Aborted due to warnings.

不确定这是否相关,但这里是 package.json 和我正在使用的系统的一些规范。

Mac OSX Yosemite
node version v5.10.1
npm 3.8.3

package.json

{
  "name": "TEST",
  "version": "1.0.0",
  "description": "test test test",
  "main": "Gruntfile.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/path/to/repo"
  },
  "author": "me <me@example.com>",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/path/to/repo/issues"
  },
  "homepage": "https://github.com/path/to/repo",
  "devDependencies": {
    "angular": "^1.5.5",
    "bootstrap-sass": "^3.3.6",
    "grunt": "^1.0.1",
    "grunt-contrib-jshint": "^1.0.0",
    "grunt-contrib-uglify": "^1.0.1",
    "grunt-contrib-watch": "^1.0.0",
    "grunt-sass": "^1.1.0",
    "jquery": "^2.2.3",
    "sass-lint": "^1.5.1"
  },
  "dependencies": {
    "jquery": "^2.2.3"
  }
}

【问题讨论】:

  • 如果我为 concat 添加另一个选项来配置,我会得到同样的错误。当我将配置添加到 Gruntfile.js 时,一切运行良好。问题似乎与 loadTasks 操作有关。我真的很希望能够从单独的配置中加载任务,因为项目会变得非常大。

标签: javascript node.js sass gruntjs


【解决方案1】:

看起来这是我的用户错误。

在任务文件中,我有 grunt.config(),但我应该有 grunt.initConfig()

var taskConfig = {
    sass : {
        options : {
            sourceMap : true,
            includePaths : 'node_modules/bootstrap-sass/assets/stylesheets'
        },
        dist : {
            files : {
                'main.css' : 'main.scss'
            }
        }
    },
    concat : {
        core : {
            src : ['node_modules/jquery/dist/jquery.js', 'js/main.js'],
            dest : "../dev/js/main.js"
        }
    }
};

module.exports = function (grunt) {
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-sass');
    grunt.initConfig(taskConfig);
    grunt.registerTask('core', ['concat:core','sass']);
};

【讨论】:

  • 更多信息,一旦我在 grunt-tasks 中添加第二个任务,initConfig() 会覆盖前一个。我正在寻找其他选项,例如 require('load-grunt-tasks')
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-01
  • 2019-10-19
  • 1970-01-01
  • 2023-03-13
  • 2014-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多