@umengfe/rollup-plugin-uapm-trycatch
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@alife/rollup-plugin-uapm-trycatch

rollup plugin 可自动对文件中存在的Catch表达式插入友盟WEB/小程序的异常上报的脚本

Usage

Install:

npm install --save-dev @alife/rollup-plugin-uapm-trycatch

Support Platform

支持平台 是否支持
WEB/H5 - [x]
微信小程序 - [x]
支付宝小程序 - [x]

Options

配置参数 是否必选 参数说明 参数类型 示例
include 包含的文件及路径规则 string[] include: ['/*.tsx', '/*.ts']
exclude 排除的文件及路径规则 string[] exclude: ['**/node_modules']
platform 目标构建平台,支持(wechat、web、alipay) string platform: 'web'

目标构建平台也可配合构建命令 通过约定的环境变量(UAPM_PLATFORM)在package.json的构建命令中进行指定,同时配置取值优先级options高于全局变量

// package.json
{
  "name": "",
  "version": "0.1.0",
  "scripts": {
    "build:h5": "cross-env UAPM_PLATFORM=web npm run build"
  }
}

Example

before:

const fn = () =>  {
  try {
    console.log(test);
  } catch (error) {}
};

after:

const fn = () =>  {
  try {
    console.log(test);
  } catch (error) {
      // WEB
+     try { window && window._apm && window._apm.captureException && window._apm.captureException(error); } catch(e){}
      // 小程序
+     try { wx && wx.umapm && wx.$umapm.captureException && wx.$umapm.captureException(error); } catch(e){}
      // 支付宝
+     try { my && my.$umapm && my.$umapm.captureException && my.$umapm.captureException(error); } catch(e){}
  }
};

How to config

.vite.config.ts

export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
+    tryCatchPlugin({
+      include: ['*.ts', '**/*.ts'],
+      platform: 'web'
+    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})

Readme

Keywords

none

Package Sidebar

Install

npm i @umengfe/rollup-plugin-uapm-trycatch

Weekly Downloads

2

Version

0.0.1

License

ISC

Unpacked Size

17.2 kB

Total Files

11

Last publish

Collaborators

  • pdap
  • umfe