2016-04-25 83 views
4

設置一個新的項目,將有多個grunt任務,我想從任務文件加載。grunt所需的配置屬性丟失

當運行我的第一個任務,'核心'這應該爲該網站的核心CSS,我收到一個錯誤,我似乎無法解決。一直在做一些谷歌搜索,沒有找到這個具體問題。任何有相同錯誤信息的問題通常都是由於OP上的錯字或錯位花括號而造成的。不知道這是這種情況,但也許別人看到我顯然沒有看到。

Gruntfile.js

module.exports = function(grunt) { 

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

    grunt.loadTasks('grunt-tasks'); 

}; 

咕嚕任務/咕嚕-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 <[email protected]>", 
    "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" 
    } 
} 
+0

如果我添加另一種選擇配置爲CONCAT,我得到同樣的錯誤。當我將配置添加到Gruntfile.js時,一切運行良好。問題似乎與loadTasks操作。我真的很希望能夠從單獨的配置中加載任務,因爲該項目將變得非常大。 – keith73

回答

2

看起來就像是用戶的錯誤在我的部分。

在任務文件

,我不得不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']); 
}; 
+0

更多信息,一旦我在grunt-tasks中添加第二個任務,initConfig()將覆蓋前一個任務。我正在尋找其他選項,如require('load-grunt-tasks') – keith73