【发布时间】:2017-06-22 14:43:11
【问题描述】:
我正在为现有项目设置 Webpack 构建过程,并且在源映射方面遇到了一些问题。
我正在使用devtool: 'eval-source-map',。如果浏览器发生错误,堆栈跟踪中的每个文件/行号都指向 Webpack 包中压缩成单行的文件。
例如,堆栈跟踪的第一行可能如下所示:
未捕获的错误:foo
在 child.initialize 处(评估在 (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',
};
对于here 列出的其他类型的开发源地图类型也会发生这种情况。如果改为使用devtool: source-map 的生产设置,我仍然会被指向一个巨大的捆绑文件,其中包含每个脚本,但至少这些行是“展开”的,我可以看到错误发生在哪里。
我该如何解决这个问题,或者至少进一步排除故障?
【问题讨论】:
-
所以您希望它在控制台中单击 filename:lineNumber 时将您定向到原始 js 文件而不是输出包?
-
至少我想让它告诉我这条线。现在在 dev 中,它会将我带到包含整个原始 JS 文件的一行,因此无法跟踪行号。
标签: javascript webpack source-maps