将 grunt 用于自定义项目

Using grunt for a custom Project

我正在使用 Grunt 作为 "JS Task Runner".
节点安装在 "C:/Program Files" 中。
NPM 安装在 C:/users/Peterson/appdata/roaming/npm 中。
npm 文件夹中的 Grunt、Bower 和 Grunt-cli。

创建项目 - D:/项目 A。
D:/ProjectA 中的以下文件 - "package.json"gruntfile.js

package.json

{
  "name": "Test-Project",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.1",
    "grunt-contrib-concat": "~0.1.3"
  }
}

gruntfile.js

module.exports = function(grunt) {

// Project configuration.
grunt.initConfig({

    //Read the package.json (optional)
    pkg: grunt.file.readJSON('package.json'),

    // Metadata.
    meta: {
        basePath: '../',
        srcPath: '../src/',
        deployPath: '../deploy/'
    },

    banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
            '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
            '* Copyright (c) <%= grunt.template.today("yyyy") %> ',

    // Task configuration.
    concat: {
        options: {
            stripBanners: true
        },
        dist: {
            src: ['<%= meta.srcPath %>scripts/fileone.js', '<%= meta.srcPath %>scripts/filetwo.js'],
            dest: '<%= meta.deployPath %>scripts/app.js'
        }
    }
});

// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-concat');

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

};

在 CLI D:/ProjectA> grunt

Fatal Error: Unable to find local grunt

有人可以帮忙吗?

您已经安装了 node/npm 和 G运行t & Bower 的 clis(我假设是通过 npm install -g 全局安装它们)

您缺少的是 运行 npm install 在项目的根目录(您的 package.json 文件所在的位置),以安装您的 项目依赖项指定在package.json