2017-02-20 126 views
0

這是我第一次測試咕嚕:)。無論如何,我想使用不同的grunt模塊來測試我的javasrcipt代碼。它們都已安裝,並且可以在名爲package.json的json文件中看到它們。咕嚕沒有定義 - AngularJs

{ 
    "name": "LarissaCity", 
    "private": true, 
    "devDependencies": { 
    "grunt": "^1.0.1", 
    "grunt-contrib-jshint": "^1.1.0", 
    "jit-grunt": "^0.10.0", 
    "jshint-stylish": "^2.2.1", 
    "time-grunt": "^1.4.0" 
    }, 
    "engines": { 
    "node": ">=0.10.0" 
    } 
} 

接下來我有一個名爲Gruntfile.js的文件。並在裏面使用已安裝的模塊來測試我的JavaScript代碼。所以。

'use strict'; 

// Time how long tasks take. Can help when optimizing build times 
require('time-grunt')(grunt); 

// Automatically load required Grunt tasks 
require('jit-grunt')(grunt); 

// Define the configuration for all the tasks 
grunt.initConfig({ 
pkg: grunt.file.readJSON('package.json'), 

// Make sure code styles are up to par and there are no obvious mistakes 
jshint: { 
options: { 
    jshintrc: '.jshintrc', 
    reporter: require('jshint-stylish') 
}, 

all: { 
    src: [ 
    'Gruntfile.js', 
    'app/scripts/{,*/}*.js' 
    ] 
    } 
} 
}); 

grunt.registerTask('build', [ 
'jshint' 
]); 

grunt.registerTask('default',['build']); 

當我鍵入咕嚕在cmd此出現。

Loading "Gruntfile.js" tasks...ERROR 
ReferenceError: grunt is not defined 

所以也許Gruntfile.js有問題。有任何想法嗎?

謝謝,

泰奧。

+2

做你'需要( '咕嚕')'的代碼? –

+0

oops。我沒有。我會在一會兒再試一次。 – Theo

+0

是的,它的工作! – Theo

回答

1

你必須寫在下面的框在gruntfile.js

module.exports = function(grunt){ 
     //Your code here 
    }