错误
使用 window.onerror 可以监听 js 错误。...// 监听 js 错误
window.onerror = (msg, url, line, column, error) => {
lazyReportCache({
msg,...line,
column,
error: error.stack,
subType: 'js',
pageURL: url.../maps/${url.split('/').pop()}.map`), 'utf-8')
}
每次项目打包时,如果开启了 sourcemap,那么每一个 js 文件都会有一个对应的 map 文件。...bundle.js
bundle.js.map
这时 js 文件放在静态服务器上供用户访问,map 文件存储在服务器,用于还原错误信息。