Skip to content

Latest commit

 

History

History
46 lines (39 loc) · 678 Bytes

README.md

File metadata and controls

46 lines (39 loc) · 678 Bytes

babel-plugin-function-try-catch

Babel plugin that can add try/catch to function automatically.

Usage

Install:

yarn add babel-plugin-function-try-catch
or
npm install babel-plugin-function-try-catch

Example

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);
  }
};

How to config

webpack:

rules: [{
  test: /\.js$/,
  exclude: /node_modules/,
  use: [
+    "babel-plugin-function-try-catch",
    "babel-loader",
  ]
}]