我正在制作一个基本的 grunt 文件来启动我的 express.js 服务器。我知道有一个专门用于此目的的插件,但出于学习目的,我想手工完成。我在运行 grunt 时收到连接未定义消息。但是,据我所知,它已经定义好了。
错误信息:
one@localhost ~/app/yo $ grunt
Running "default" task
Warning: connect is not defined Use --force to continue.
Aborted due to warnings.
one@localhost ~/app/yo $
Gruntfile.js:
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
servedFiles: {
files: '<%= pkg.name %>/static/**',
options: {
livereload: true
}
},
},
connect: {
options: {
port: 8000,
hostname: '0.0.0.0',
livereload: 35729
},
},
});
grunt.registerTask('default', 'start server', function() {
grunt.task.run(connect);
});
}
Grunt 模块:
one@localhost ~/app/yo $ lr node_modules/
total 68k
drwxr-xr-x 8 one users 8 Apr 26 17:54 .
drwxr-xr-x 4 one users 7 Apr 26 18:23 ..
drwxr-xr-x 2 one users 3 Apr 25 21:11 .bin
drwxr-xr-x 5 one users 13 Apr 25 21:11 express
drwxr-xr-x 5 one users 9 Apr 26 17:54 grunt
drwxr-xr-x 4 one users 7 Apr 26 17:54 grunt-contrib-connect
drwxr-xr-x 4 one users 7 Apr 26 17:54 grunt-contrib-watch
drwxr-xr-x 3 one users 6 Apr 25 21:37 load-grunt-tasks
one@localhost ~/app/yo $
最佳答案
错误是因为 connect
没有被定义为变量:
grunt.task.run(connect);
// ^ ReferenceError
如果先声明它,它可以作为一个使用:
var connect = 'connect';
但是,否则它应该是 Grunt 可以用来查找已注册任务的 String
值:
grunt.task.run('connect');
关于javascript - Node Grunt.js 'Warning: connect is not defined Use ',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23317629/