这个插件可以自动帮你收集异常到数组:window.__elog
中。
In
try {
// your code
} catch (e) {
// your exception handler code
}
Out
try {
// your code
} catch (e) {
__elog.push(e) // this babel plugin will add this line automatic.
// your exception handler code
}
$ npm install @qnpm/babel-plugin-catch-log
.babelrc
{
"plugins": ["@qnpm/babel-plugin-catch-log"]
}
$ babel --plugins @qnpm/babel-plugin-catch-log script.js
require("babel-core").transform("code", {
plugins: ["@qnpm/babel-plugin-catch-log"]
});