我试图从一个简单的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

我想念什么吗?

最佳答案

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

grunt

使用以下命令安装grunt-contrib-concat:

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


Package.json应该具有以下内容:

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

关于javascript - 严重警告:未找到任务“concat”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30988252/

10-16 19:32