Babel plugin that can add
try/catch
to function automatically.
Install:
yarn add babel-plugin-function-try-catch
or
npm install babel-plugin-function-try-catch
before:
var fn = function(){
console.log('hello world');
}
after:
var fn = function () {
try {
console.log(2);
} catch (error) {
// you can do some stuff here, for example, report this error with monitor sdk.
console.log(error);
}
};
webpack:
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: [
+ "babel-plugin-function-try-catch",
"babel-loader",
]
}]