用Intellij调试grunt [英] Debugging grunt with Intellij

查看:157
本文介绍了用Intellij调试grunt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Intellij(IDEA)调试grunt。
技术是:NodeJS,express,AngularJS。

问题:
调试器不会在断点停止。



我很乐意听到您的想法。

配置选项卡:

节点解释器:C:\ Program Files \\\
odejs\\\
ode.exe

Javscript文件:C:\ Users [user] \AppData\Roaming\\\
pm\\\
ode_modules\grunt-cli\bin\ grunt



浏览器/实时编辑标签:

  http :// localhost:3000 / 

这里是Gruntfile.js:

  var path = require('path'); 

module.exports = function(grunt){

grunt.initConfig({
express:{
dev:{
options: {
script:'server.js'
}
},
},
观看:{
html:{
files:[ '** / *。html'],
选项:{
livereload:true
}
},
服务器:{
files:[' server.js'],
tasks:['express:dev'],
options:{
livereload:true,
spawn:false //没有指定express选项'
',
js:{
files:['** / *。js'],
options:{
livereload:true
}
}
},
open:{
express:{
//从连接配置中获取端口guration
path:'http:// localhost:3000'
}
}

});

grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-express-server');
grunt.loadNpmTasks('grunt-open');

grunt.registerTask('default',['express:dev','watch'])

};

解决方案

刚刚尝试了一个示例Angular + Express应用程序作为Grunt任务运行。我用过你的Gruntfile.js(不变)。我的Node.js运行配置看起来像fololows:

配置选项卡:
节点解释器:C:\ Program Files \\\
odejs\\\
ode.exe
Javscript文件:C:\ Users [user] \AppData\Roaming\\\
pm\\\
ode_modules\grunt-cli\bin\grunt
工作目录:我的项目根目录 - 文件夹Gruntfile.js位于

实时编辑标签:
启动后启用
启用JavaScript Debugger

  http:// localhost:3000 

我在我的controllers.js中设置了断点,并按照预期在Angular代码工作中的调试器=>断点处运行上面的配置。我的服务器代码中的断点不会:)

为了让服务器端代码中的断点起作用,我做了以下操作:




  • 在Gruntfile.js中添加了'debug:true'以开启选项:

  • :{
    dev:{
    options:{
    script:'server.js',
    debug:true
    }
    }
    } ,


    • 修改了node_modules\grunt-express-server\tasks\lib\server.js,第65行,将' --debug'to'--debug-brk ='('--debug-brk = 47977'in my case)


    I'm trying to debug grunt with Intellij (IDEA). The technologies are: NodeJS, express, AngularJS.

    The problem: Debugger does not stop on breakpoints.

    I'll be happy to hear your thoughts.

    configuration tab:
    Node interpreter: C:\Program Files\nodejs\node.exe
    Javscript file: C:\Users[user]\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt

    Browser / Live Edit tab:

    http://localhost:3000/
    

    and here is the Gruntfile.js:

    var path = require('path');
    
    module.exports = function (grunt) {
    
    grunt.initConfig({
        express: {
            dev: {
                options: {
                    script: 'server.js'
                }
            },
        },
        watch: {
            html: {
                files: [ '**/*.html'],
                options: {
                    livereload: true
                }
            },
            server: {
                files: [ 'server.js'],
                tasks: ['express:dev'],
                options: {
                    livereload: true,
                    spawn: false // Without this option specified express won't be reloaded
                }
            },
            js: {
                files: [ '**/*.js'],
                options: {
                    livereload: true
                }
            }
        },
        open: {
            express: {
                // Gets the port from the connect configuration
                path: 'http://localhost:3000'
            }
        }
    
    });
    
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-express-server');
    grunt.loadNpmTasks('grunt-open');
    
    grunt.registerTask('default', ['express:dev', 'watch' ])
    

    };

    解决方案

    Just tried a sample Angular+Express application run as a Grunt task. I've used your Gruntfile.js (unchanged). My Node.js Run configuration looks as fololows:

    configuration tab: Node interpreter: C:\Program Files\nodejs\node.exe Javscript file: C:\Users[user]\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt Working directory: my project root - the folder where Gruntfile.js is located

    Live Edit tab: After launch enabled with JavaScript Debugger enabled

    http://localhost:3000
    

    I set breakpoints in my controllers.js and run the configuration above in debugger => breakpoints in Angular code work as expected. Breakpoints in my server code don't :)

    To get breakpoints in server-side code working, I did the following:

    • added 'debug: true' to dev options in Gruntfile.js:

    express: { dev: { options: { script: 'server.js', debug: true } } },

    • modified the node_modules\grunt-express-server\tasks\lib\server.js, line 65, changing '--debug' to '--debug-brk=' ('--debug-brk=47977' in my case)

    这篇关于用Intellij调试grunt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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