webstorm 7 / karma服务器在调试coffeescript时查找错误的sourcemap文件 [英] webstorm 7/karma server looking for wrong sourcemap file when debugging coffeescript

查看:821
本文介绍了webstorm 7 / karma服务器在调试coffeescript时查找错误的sourcemap文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个时间试图让调试器使用我的coffeescript文件在测试与karma测试跑者时的恶魔。

I am having a devil of a time trying to get the debugger to work with my coffeescript files when testing with the karma test runner.

假设,我需要做的是告诉Webstorm文件观察者生成源映射,调试器将与karma测试运行器一起工作。不幸的是,调试器似乎不识别由coffeescript编译器输出的映射文件。它寻找file.coffee - > file.js.map。然而,尽管尝试得到一些其他结果地图文件总是file.coffee - > file.map

Supposedly, all I need to do is tell the Webstorm file watcher to generate sourcemaps and the debugger will work with the karma test runner. Unfortunately, the debugger doesn't seem to recognize the map file output by the coffeescript compiler. It looks for file.coffee -> file.js.map. However, despite trying to get some other result the map file is always file.coffee -> file.map

我的karma配置文件有以下(显然不是整个事情,只是相关的部分):

my karma config file has the following (obviously not the whole thing, just the relevant parts):

module.exports = (config) ->
  config.set
    files: [
      '../app/scripts/**/*.coffee'
      'spec/*.coffee']
    preprocessors: {
      '../**/*.coffee': 'coffee'
    }

我已经尝试过与文件监视器的各种配置:

I have tried all kinds of configurations with the file watchers:

一个单文件监视器参数: - compile --bare --map $ FileName $,输出路径刷新为:$ FileNameWithoutExtension $ .js.map或$ FileNameWithoutExtension $ .js:$ FileNameWithoutExtension $ .js.map

A single file watcher with the arguments:"--compile --bare --map $FileName$" with the Output paths to refresh as either: "$FileNameWithoutExtension$.js.map" or "$FileNameWithoutExtension$.js:$FileNameWithoutExtension$.js.map"

第一个版本生成一个空白file.js.map,第二个生成一个空白file.js.map和标准file.map这是一个很好的源映射文件。

The first version produces an blank file.js.map, the second produces a blank file.js.map AND the standard file.map which is a good sourcemap file.

我试过一个文件监视器只有--compile --bare输出路径:$ FileNameWithoutExtension $ .js,第二个只有--map输出路径:$ FileNameWithoutExtension $。 js.map。

I've tried one file watcher that just has "--compile --bare" Output path: "$FileNameWithoutExtension$.js" and a second that just has "--map" Output path: "$FileNameWithoutExtension$.js.map". That outputs a blank file.js.map and no actual map.

我试过一个文件监视器只有--compile --bare输出路径: $ FileNameWithoutExtension $ .js,第二个只有--compile --map输出路径:$ FileNameWithoutExtension $ .js.map。

I've tried one file watcher that just has "--compile --bare" Output path: "$FileNameWithoutExtension$.js" and a second that just has "--compile --map" Output path: "$FileNameWithoutExtension$.js.map". That outputs a blank file.js.map and no actual map.

同时,当我以调试模式运行测试时,Karma Server报告:

Meanwhile, when I run the test in debug mode the Karma Server reports:

WARN [web-server]: 404: /base/spec/schedule-spec.js.map?time=1380945586331
WARN [web-server]: 404: /absolute/Users/Randolph/Documents/Sites/MTF-Minimal/app/scripts/app.js.map?time=1380945586083
etc...

很明显,服务器假定映射将被称为file.js.map,当事实上coffeescript输出file.map没有js 。我似乎不能改变什么输出源映射文件被调用,我不知道在哪里告诉调试器什么寻找。

Clearly the server is assuming the map will be called file.js.map, when in fact coffeescript outputs file.map without the "js". I can't seem to change what the output sourcemap file is called and I don't see where to tell the debugger what to look for.

附带地,调试器还告诉我,它找不到加载了我的文件如angular.js和jquery.js的非coffeescript库的地图文件。也许这是一个线索的错误。

Parenthetically, the debugger is also telling me that it can't find map files for non-coffeescript libraries loaded with my files like angular.js and jquery.js. Perhaps that is a clue to what is wrong.

我已经提交了票,JetBrains,并将分享他们在这里回复,以及。

I have submitted a ticket to JetBrains, and will share what they respond here as well. However, if anyone knows the solution please let me know.

推荐答案

使调试器使用由文件监视器生成的.js和.map文件的唯一方法是将这些生成的.js文件加载到您的karma配置文件中,而不是.coffee文件。当你加载.coffee文件时,karma实际上不是由transpiler产生的文件,而是由咖啡预处理器生成的.js文件,这些文件没有生成源映射,所以调试器不知道如何映射它们您的咖啡文件。这里有两个选项:

The only way to make debugger use the .js and .map files generated by file watcher is to load these generated .js files in your karma configuration file instead of .coffee files. As you load .coffee files instead, karma is actually serving not the files produced by transpiler, but .js files generated by coffee preprocessor, and these files don't have source maps generated, so the debugger has no idea how to map them to your coffee files. You have 2 options here:


  • 在您的karma配置文件中加载由文件监视器生成的.js文件,

files: [
'../app/scripts/**/*.js'
'spec/*.js'
]




  • 在karma中配置coffeePreprocessor以使用源映射,例如:

  • files: [
    '../app/scripts/**/*.coffee'
    'spec/*.cofee'
    ],
    preprocessors: {
                '**/*.coffee': ['coffee']
            },
    coffeePreprocessor: {
                options: {
                    bare: true,
                    sourceMap: true
                },
                // transforming the filenames
                transformPath: function ( path ) {
                    return path.replace( /\.js$/, '.coffee' );
                }
            },
    ...
    

    要使用第二个选项,您需要确保使用最新版本的karma和karma-coffee-preprocessor

    To be able to use the second option you need to make sure to use the most recent versions of karma and karma-coffee-preprocessor

    这篇关于webstorm 7 / karma服务器在调试coffeescript时查找错误的sourcemap文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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