我正在为一个现有项目设置Webpack构建过程,但在源代码映射方面遇到了一些问题。
我正在使用devtool: 'eval-source-map'
。如果浏览器中发生错误,则栈跟踪中的每个文件/行号都指向在Webpack捆绑包中压缩为单行的文件。
例如,堆栈跟踪的第一行可能如下所示:
Uncaught Error: foo
at child.initialize (eval at (http://127.0.0.1:8000/js/dist/index.js:1270:1), :45:10)
单击文件名/行号会将我带到捆绑包中由Webpack“包含”错误发生的文件所在的行。看起来像这样:
/* 223 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
// Below is the line it points to, and it goes on to have the entire file on the same line
eval("/* WEBPACK VAR INJECTION */(function(Backbone, $, _) { ...
然而,整个文件内容都在单行上,因此这是完全无用的。
即使我将Webpack配置仅裁剪到以下内容,仍会发生这种情况:
var path = require('path'),
webpack = require('webpack');
module.exports = {
entry: {
'indexhead': './static/js/main.js',
'accounthead': './static/js/accountManager.js'
},
output: {
path: path.join(__dirname, 'static/js/dist'),
filename: '[name].js'
},
devtool: 'eval-source-map',
};
如果涉及其他类型的开发源映射类型,请参见此处概述。如果我使用devtool:source-map
的生产设置,仍然会指向一个包含每个脚本的巨大捆绑文件,但至少行是“展开的”,我可以看到错误发生的位置。
我该如何修复这个问题,或者至少进一步排除故障?