2016-04-25 10 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']); 

私はこのエラーを取得する:これは関連性があるが、ここではシステム上のpackage.jsonと一部仕様がある場合は私が使用している

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

Aborted due to warnings. 

わかりません。それは私の部分にユーザーのエラーだったよう

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

私は連結のための設定への別のオプションを追加した場合、私は同じエラーを取得します。 Gruntfile.jsに設定を追加すると、すべて正常に動作します。問題は、loadTasks操作と思われる。プロジェクトがかなり大きくなるので、私は本当に別のconfigsからタスクを読み込むことができるようにしたいと思います。 – 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

more info、grunt-tasksで2番目のタスクを追加すると、initConfig()は前のタスクを上書きします。私はrequire( 'load-grunt-tasks')のような他のオプションを見ています – keith73

関連する問題