Grunt警告:任务" concat"找不到

时间:2015-06-22 19:29:43

标签: javascript node.js gruntjs npm grunt-contrib-concat

我试图开始使用一个简单的Grunt示例,但我遇到了 grunt-contrib-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 install并不会显示任何明显的错误:

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

以下是我的目录结构:

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

当我运行grunt 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,grunt-cli:v0.1.13,grunt:v0.4.5

我错过了什么吗?

1 个答案:

答案 0 :(得分:2)

您应该将其运行为:grunt而不是concat,因为任务是default。运行它不需要任何参数。因此,启动命令变得简单:

grunt

使用它来安装grunt-contrib-concat:

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

Package.json应该是这样的:

"devDependencies": {
  "grunt-contrib-concat": "^0.5.1"
},  
相关问题