Grunt不会加载节点服务器 [英] Grunt won't load the node server

查看:163
本文介绍了Grunt不会加载节点服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 gruntfile.js 是:

 'use strict' ; 

module.exports = function(grunt){
// Project Configuration
grunt.initConfig({
pkg:grunt.file.readJSON('package.json '),
watch:{
jade:{
files:['app / views / **'],
options:{
livereload:true,
},
},
js:{
files:['gruntfile.js','server.js','app / ** / *。js','public / js / **','test / ** / *。js'],
任务:['jshint'],
选项:{
livereload:true,
},
},
html:{
files:['public / views / **'],
options:{
livereload:true,
$,
},
css:{
files:['public / css / **'],
options:{
livereload:true
}
}
},
jshint:{
all:{
src:['gruntfile.js',' server.js','app / ** / *。js','public / js / **','test / ** / *。js'],
选项:{
jshintrc: true
}
}
},
nodemon:{
dev:{
options:{
file:'server.js',
args:[],
ignoredFiles:['public / **'],
watchedExtensions:['js'],
nodeArgs:['--debug'],
delayTime:1,
env:{
PORT:3000
},
cwd:__dirname
}
}
} ,
并发:{
任务:['nodemon','watch'],
选项:{
logConcurrentOutput:true
}
},
mochaTest:{
options: {
记者:'spec',
需要:'server.js'
},
src:['test / mocha / ** / *。js']
$ b env:{
test:{
NODE_ENV:'test'
}
},
karma:{
unit :{
configFile:'test / karma / karma.conf.js'
}
}
});

//载入NPM任务
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-env');

//使grunt默认为强制以不中断项目。
grunt.option('force',true);

//默认任务。
grunt.registerTask('default',['jshint','concurrent']);

//测试任务。
grunt.registerTask('test',['env:test','mochaTest','karma:unit']);
};

当我输入 grunt 时,我得到:

  $ grunt 
运行jshint:all(jshint)任务
>> 69个文件免费。

运行concurrent:tasks(并发)任务
运行nodemon:dev(nodemon)任务
运行watch任务
等待...

通常它表示 Express在端口3000上启动,但突然不是。不知道发生了什么事。任何想法?



当使用 -v 标志运行时,我得到:

 运行任务:nodemon 

运行nodemon任务

运行nodemon:dev(nodemon)任务
验证属性nodemon.dev存在于config中... OK
文件:[no files]
选项:file =server.js,args = [],ignoredFiles = [ public / **],watchedExtensions = [js],nodeArgs = [ - debug],delayTime = 1,env = {PORT:3000},cwd =/ Users / shamoon / Sites / blocksearcher
加载env.js任务... OK
+ env
加载gruntfile.js任务... OK
+ default,test

运行任务:观看

运行观看任务
等待...验证属性观察存在于配置中... OK
验证属性watch.jade.files存在在配置中... OK
验证属性watch.js.files存在于config中... OK
验证属性watch.html.files存在于config中... OK
验证属性监视。 css.fil es存在于配置中...
实时重新加载服务器在端口上启动:35729


观看应用程序/视图以进行更改。
观看应用程序/视图/包含更改。
...


解决方案

grunt-nodemon: https://github.com/ChrisWren/grunt-nodemon#changelog

您最近必须更新您的依赖项,而grunt-nodemon更改了一些属性。

   - 文件现在是脚本
- ignoredFiles - >忽略
- watchedFolders - >观看
- watchedExtensions - > ext


My gruntfile.js is:

'use strict';

module.exports = function(grunt) {
    // Project Configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        watch: {
            jade: {
                files: ['app/views/**'],
                options: {
                    livereload: true,
                },
            },
            js: {
                files: ['gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js'],
                tasks: ['jshint'],
                options: {
                    livereload: true,
                },
            },
            html: {
                files: ['public/views/**'],
                options: {
                    livereload: true,
                },
            },
            css: {
                files: ['public/css/**'],
                options: {
                    livereload: true
                }
            }
        },
        jshint: {
            all: {
                src: ['gruntfile.js', 'server.js', 'app/**/*.js', 'public/js/**', 'test/**/*.js'],
                options: {
                    jshintrc: true
                }
            }
        },
        nodemon: {
            dev: {
                options: {
                    file: 'server.js',
                    args: [],
                    ignoredFiles: ['public/**'],
                    watchedExtensions: ['js'],
                    nodeArgs: ['--debug'],
                    delayTime: 1,
                    env: {
                        PORT: 3000
                    },
                    cwd: __dirname
                }
            }
        },
        concurrent: {
            tasks: ['nodemon', 'watch'],
            options: {
                logConcurrentOutput: true
            }
        },
        mochaTest: {
            options: {
                reporter: 'spec',
                require: 'server.js'
            },
            src: ['test/mocha/**/*.js']
        },
        env: {
            test: {
                NODE_ENV: 'test'
            }
        },
        karma: {
            unit: {
                configFile: 'test/karma/karma.conf.js'
            }
        }
    });

    //Load NPM tasks 
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-mocha-test');
    grunt.loadNpmTasks('grunt-karma');
    grunt.loadNpmTasks('grunt-nodemon');
    grunt.loadNpmTasks('grunt-concurrent');
    grunt.loadNpmTasks('grunt-env');

    //Making grunt default to force in order not to break the project.
    grunt.option('force', true);

    //Default task(s).
    grunt.registerTask('default', ['jshint', 'concurrent']);

    //Test task.
    grunt.registerTask('test', ['env:test', 'mochaTest', 'karma:unit']);
};

and when I type grunt, I get:

$ grunt
Running "jshint:all" (jshint) task
>> 69 files lint free.

Running "concurrent:tasks" (concurrent) task
Running "nodemon:dev" (nodemon) task
Running "watch" task
Waiting...

Usually it says Express started on Port 3000, but suddenly it isn't. Not sure what's going on. Any ideas?

When running with the -v flag, I get:

Running tasks: nodemon

    Running "nodemon" task

    Running "nodemon:dev" (nodemon) task
    Verifying property nodemon.dev exists in config...OK
    File: [no files]
    Options: file="server.js", args=[], ignoredFiles=["public/**"], watchedExtensions=["js"], nodeArgs=["--debug"], delayTime=1, env={"PORT":3000}, cwd="/Users/shamoon/Sites/blocksearcher"
    Loading "env.js" tasks...OK
    + env
    Loading "gruntfile.js" tasks...OK
    + default, test

    Running tasks: watch

    Running "watch" task
    Waiting...Verifying property watch exists in config...OK
    Verifying property watch.jade.files exists in config...OK
    Verifying property watch.js.files exists in config...OK
    Verifying property watch.html.files exists in config...OK
    Verifying property watch.css.files exists in config...OK
    Live reload server started on port: 35729


        Watching app/views for changes.
    Watching app/views/includes for changes.
    ...

解决方案

Look at the changelog of grunt-nodemon: https://github.com/ChrisWren/grunt-nodemon#changelog.

You must have update your dependencies recently and grunt-nodemon changed a few properties.

- file is now script
- ignoredFiles -> ignore
- watchedFolders -> watch
- watchedExtensions -> ext

这篇关于Grunt不会加载节点服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆