2

簡単な 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

何か不足していますか?

4

1 に答える 1

3

gruntタスクconcatとして実行する必要がありますdefault。実行するのに引数は必要ありません。したがって、起動するコマンドは次のようになります。

grunt

これを使用して、grunt-contrib-concat をインストールします。

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

Package.json は次のようになります。

"devDependencies": {
  "grunt-contrib-concat": "^0.5.1"
},  
于 2015-06-22T20:02:45.290 に答える