我正在使用grunt-contrib-uglify插件来压缩我的javascript源文件以用于生产。
当我尝试在chrome的dev-tools (或firefox)中调试函数时,出现了这个问题。
我在Gruntfile.js的uglify task config中设置了mangle:true (默认值),并在生成的代码中破坏(缩短并重命名)了变量名。
这些变量未正确映射到其原始局部变量名。所以调试是非常痛苦的。
有什么办法来解决这个问题吗?
下面是我的Gruntfile.js
/* global module */
module.exports = function (grunt) {
grunt.initConfig({
copy: {
production: {
files: [
{
expand: true,
cwd: "./development/js/",
src: "./*",
dest: "./production/js/debug/"
}
]
}
},
uglify: {
production: {
options: {
sourceMap: true
/* mangle: false */
},
files: {
"./production/js/one.min.js": ["./development/js/one.js"],
"./production/js/two.min.js": ["./development/js/two.js"]
//"./production/js/app.js": ["./development/js/one.js" , "./development/js/two.js" ]
}
}
}
});
// [STEP] Load required GRUNT plugins
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
// [STEP] Register tasks
grunt.registerTask("default", ["copy:production", "uglify:production"]);
};
我的目录结构基本上是,
Project ROOT dir
--F-- package.json
--F-- Gruntfile.json
--D-- node_modules
--*---- * (module files folders)
--D-- development
--D---- js
--F------ one.js
--F------ two.js
--D-- production
--D---- js (generated from grunt)
--*------ * (generated files)
--D------ debug (generated from grunt)
--*-------- * (generated files)
--F---- index.html发布于 2015-12-03 06:58:34
这里也问了一个类似的问题:Breakpoint debugging minfied/mangled/compiled variables
今天我遇到了这个问题。这在Chrome和Firefox中似乎是一致的行为,这表明这是源码映射规范中的一个限制。
Chromium有一个开放的问题:https://code.google.com/p/chromium/issues/detail?id=327092建议需要更新源代码映射规范来适应这一点。
如果您在精简代码时使用名称损坏,或者代码被转译(例如,编写通过Babel传递的ES2015 ),则会出现此问题。似乎目前的解决方案是等待源映射更新来处理这种转换。
https://stackoverflow.com/questions/29718639
复制相似问题