【问题标题】:Debugging grunt with Intellij使用 Intellij 调试 grunt
【发布时间】:2014-02-22 17:01:35
【问题描述】:

我正在尝试使用 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/

这里是 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' ])

};

【问题讨论】:

标签: node.js intellij-idea gruntjs webstorm


【解决方案1】:

刚刚尝试了一个作为 Grunt 任务运行的示例 Angular+Express 应用程序。我使用了您的 Gruntfile.js(未更改)。我的 Node.js 运行配置如下所示:

配置选项卡: 节点解释器: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

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

为了让服务器端代码中的断点正常工作,我执行了以下操作:

  • 在 Gruntfile.js 的开发选项中添加了“debug: true”:

快递:{ 开发:{ 选项: { 脚本:'server.js', 调试:真 } } },

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

【讨论】:

    【解决方案2】:

    尝试为 chrome 安装 JetBrains IDE 支持扩展,然后创建一个 javascript 调试配置,如下所示:
    (来源:ignaciosuay.com

    我的 grunt 服务器在端口 9000 中运行,所以将其更改为 3000。 注意:您需要在运行此配置之前运行 grunt。 如果您有任何疑问,请查看此post,其中逐步解释了如何使用 Intellij 调试 AngularJS。

    【讨论】:

      猜你喜欢
      • 2013-07-06
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-26
      • 2016-07-01
      相关资源
      最近更新 更多