2013-07-08 98 views
3

我正在啓動一個新的Web項目,並且我的配置的最後一部分是爲我的CoffeeScripts文件啓用調試。使用IntelliJ對CoffeeScript進行調試

整個項目是使用Grunt任務構建的,該任務將咖啡編譯爲js並生成適當的映射文件,但我無法在IntelliJ中使Coffeescript調試工作。

請注意,我不想使用IntelliJ File Watchers。

這裏是我的Gruntfile:

module.exports = (grunt) -> 
    grunt.initConfig 
    pkg: grunt.file.readJSON('package.json') 
    coffee: 
     options: 
     sourceMap: true 
     files: 
     expand: true 
     flatten: true 
     cwd: 'src/' 
     src: ['**/*.coffee'] 
     dest: 'src/' 
     ext: '.js' 
    concat: 
     option: 
     separator: ';' 
     dist: 
     src: ['src/**/*.js'] 
     dest: 'dist/<%= pkg.name%>.js' 
    uglify: 
     options: 
     banner: '/*! <%= pkg.name %> v<%= pkg.version%> by Pierre Degand <%= grunt.template.today("dd-mm-yyyy") %> */\n' 
     dist: 
     files: 
      'lib/<%= pkg.name%>.min.js': ['<%= concat.dist.dest %>'] 
    watch: 
     files: ['<%= coffee.files.src %>'] 
     tasks: ['coffee', 'concat', 'uglify'] 

    grunt.loadNpmTasks('grunt-contrib-concat') 
    grunt.loadNpmTasks('grunt-contrib-uglify') 
    grunt.loadNpmTasks('grunt-contrib-coffee') 
    grunt.loadNpmTasks('grunt-contrib-watch') 

    grunt.registerTask('default', ['coffee', 'concat', 'uglify']) 

我的簡單的CoffeeScript文件(斷點上線2的IntelliJ):

name = 'Pierre' 
console.log "Hello #{name} !" 

生成從步兵JS文件:

(function() { 
    var name; 

    name = 'Pierre'; 

    console.log("Hello " + name + " !!"); 

}).call(this); 

/* 
//@ sourceMappingURL=app.js.map 
*/ 

源圖

{ 
    "version": 3, 
    "file": "app.js", 
    "sourceRoot": "", 
    "sources": [ 
    "app.coffee" 
    ], 
    "names": [], 
    "mappings": "AAAA;CAAA,GAAA,EAAA;;CAAA,CAAA,CAAO,CAAP,IAAA;;CAAA,CACA,CAAA,CAAa,CAAb,EAAO,CAAM;CADb" 
} 

最後我用HTML來測試

<!DOCTYPE html> 
<html> 
<head> 
    <title></title> 
</head> 
<body> 

<script type="text/javascript" src="src/app.js"></script> 
</body> 
</html> 

當我使用的文件觀察家的.js文件和.map.js是在.coffee文件的子文件,我可以達到同樣的行爲,而不使用文件觀察者?

如果我在IntelliJ中右鍵單擊/「Debug index.html」,我可以閱讀「Hello Pierre !!」在我的IntelliJ debuger控制檯中,但腳本沒有打破console.log()

有人遇到過同樣的麻煩嗎?

謝謝!

回答

1

當我使用File觀察者時,.js和.map.js是.coffee文件的子文件,我可以在不使用File Watchers的情況下實現相同的行爲嗎?

不,你不能。這是一個文件觀察器功能

如果我在IntelliJ中右鍵單擊/「調試index.html」,我可以閱讀「Hello Pierre !!」在我的IntelliJ debuger控制檯,但劇本沒有breaked上的console.log()

這個工作對我來說,如果我在瀏覽器中刷新頁面被執行的代碼之後。請投票給this ticket