使用Intellij调试grunt

che*_*nop 5 intellij-idea node.js webstorm gruntjs

我正在尝试用Intellij(IDEA)调试grunt.这些技术是:NodeJS,express,AngularJS.

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

我很乐意听到你的想法.

配置选项卡:
节点解释器:C:\ Program Files \nodejs \node.exe
Javscript文件:C:\ Users [user]\AppData\Roaming \npm \node_modules\grunt-cli\bin\grunt

浏览器/实时编辑选项卡:

http://localhost:3000/
Run Code Online (Sandbox Code Playgroud)

这是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' ])
Run Code Online (Sandbox Code Playgroud)

};

len*_*ena 6

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

配置选项卡:节点解释器:C:\ Program Files \nodejs \node.exe Javscript文件:C:\ Users [user]\AppData\Roaming \npm \node_modules\grunt-cli\bin\grunt工作目录:我的项目根目录 - Gruntfile.js所在的文件夹

"实时编辑"选项卡:启用启用JavaScript调试器启动后

http://localhost:3000
Run Code Online (Sandbox Code Playgroud)

我在controllers.js中设置了断点,并在Angular代码中的debugger => breakpoints中按预期运行上面的配置.我的服务器代码中的断点不:)

为了使服务器端代码中的断点工作,我做了以下事情:

  • 将'debug:true'添加到Gruntfile.js中的dev选项:

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

  • 修改了node_modules\grunt-express-server\tasks\lib\server.js,第65行,将'--debug'改为'--debug-brk ='(在我的情况下'--debug-brk = 47977')