Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

node.js - Debugging grunt with Intellij

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 odejs ode.exe
Javscript file: C:Users[user]AppDataRoaming pm ode_modulesgrunt-cliingrunt

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' ])

};

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 odejs ode.exe Javscript file: C:Users[user]AppDataRoaming pm ode_modulesgrunt-cliingrunt 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_modulesgrunt-express-serveraskslibserver.js, line 65, changing '--debug' to '--debug-brk=' ('--debug-brk=47977' in my case)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...