简体   繁体   中英

Using grunt for a custom Project

I am using Grunt as "JS Task Runner".
Node is installed in "C:/Program Files".
NPM got installed in C:/users/Peterson/appdata/roaming/npm.
Grunt, Bower, and Grunt-cli inside npm folder.

Creating a project - D:/Project A.
Following files inside D:/ProjectA - "package.json" and 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']);

};

In CLI D:/ProjectA> grunt

Fatal Error: Unable to find local grunt

Can someone help?

You have installed node/npm and the clis of Grunt & Bower (installing them globally via npm install -g I assume)

What you're missing is to run npm install at the root of your project (where your package.json file is), to install your project dependencies specified in the package.json

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM