2015-06-22 72 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,却是另一位“故宫安装”,这一次它的工作。不知道它为什么会出错,但谢谢! –

相关问题