2015-06-22 73 views
2

我想嘗試一個簡單的Grunt示例,但我遇到了一個問題grunt-contrib-concatGrunt警告:找不到任務「concat」

這裏是我的Gruntfile.js:

$ cat Gruntfile.js 
module.exports = function(grunt) { 
    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    concat: { 
     options: { 
     separator: ';' 
     }, 
     dist: { 
     src: ['src/**/*.js'], 
     dest: 'dist/<%= pkg.name %>.js' 
     } 
    } 
    }); 

    grunt.loadNpmTasks('grunt-contrib-concat'); 

    grunt.registerTask('default', ['concat']); 

和我的package.json:

$ cat package.json 
{ 
    "name": "Linker", 
    "version": "0.0.0", 
    "description": "A test project that is meant to be a dependency", 
    "repository": { 
    "type": "git", 
    "url": "git://github.com/jonbri/Linker.git" 
    }, 
    "main": "src/index.js", 
    "scripts": { 
    "test": "echo \"Error: no test specified\" && exit 1" 
    }, 
    "dependencies": { 
     "grunt-contrib-concat": "*" 
    }, 
    "author": "", 
    "license": "ISC" 
} 

運行NPM安裝不顯示任何明顯的錯誤:

$ npm install 
$ ls node_modules/ 
grunt grunt-contrib-concat 

這裏什麼我的目錄結構如下:

$ ls 
Gruntfile.js node_modules package.json README.md src 
$ ls src 
index.js 

當我運行咕嚕CONCAT我得到這個:

$ grunt concat 
Loading "concat.js" tasks...ERROR 
>> Error: Cannot find module 'ansi-styles' 
Warning: Task "concat" not found. Use --force to continue. 

Aborted due to warnings. 

我的設置:

Lubuntu 12.10,節點:v0.10.25,NPM:1.4.21,咕嚕-CLI:v0.1.13 ,咕嚕:v0.4.5

我這麼想嗎?

回答

2

您應該將其運行爲:grunt沒有concat,因爲任務是default之一。運行它不需要參數。於是命令來啓動變得簡單:

grunt

使用此安裝咕嚕-的contrib-CONCAT:

npm install grunt-contrib-concat --save-dev 

的package.json應該有這樣的事情:

"devDependencies": { 
    "grunt-contrib-concat": "^0.5.1" 
}, 
+0

謝謝對於但當我與無參數運行,我得到完全相同的輸出 –

+0

我沒有運行任何問題,你可以嘗試刪除node_modules並重新安裝咕嚕-CON TRIB-CONCAT? –

+0

奇怪......我刪除node_modules,卻是另一位「故宮安裝」,這一次它的工作。不知道它爲什麼會出錯,但謝謝! –

相關問題