javascript 使用 grunt 从 browserify 生成源映射

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23949262/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 01:52:30  来源:igfitidea点击:

Generating source maps from browserify using grunt

javascriptgruntjsbrowserifycommonjs

提问by Amal Antony

I have followed the instructions here: https://www.npmjs.org/package/grunt-browserify, to try and set up source maps for browserify on grunt. The options for browserify in my gruntfile are :

我已按照此处的说明进行操作:https: //www.npmjs.org/package/grunt-browserify,尝试为 grunt 上的 browserify 设置源映射。我的 gruntfile 中的 browserify 选项是:

browserify: {
            options: {
                bundleOptions : {
                    debug: true 
                }
            },
            dist: {
                files: {
                    "public/client.bundle.js": ["bundle.js"]
                }
            }
        }

The generation of bundle.js happens without any issues, however the source map generation does not happen. Is there anything wrong with my grunt-browserify options.

bundle.js 的生成没有任何问题,但是 source map 生成没有发生。我的 grunt-browserify 选项有什么问题吗。

Thanks for looking.

谢谢你看。

回答by knpsck

use browserifyOptions instead of bundleOptions

使用 browserifyOptions 而不是 bundleOptions

browserify: {
   options: {
      browserifyOptions: {
         debug: true
      }
   },
   ...
}

回答by hurrymaplelad

By default, browserify generates inline source maps as a comment in bundle.js. Browserify's README suggests using exorcistif you want to extract them to a separate file:

默认情况下,browserify 生成内联源映射作为bundle.js. Browserify 的README 建议使用exorcist如果你想将它们解压到一个单独的文件中:

$ browserify main.js --debug | exorcist bundle.js.map > bundle.js 

And grunt-extract-sourcemaprolls this up in a grunt task

并且grunt-extract-sourcemap在 grunt 任务中将其汇总