😄
前端学习
  • 👋Welcome
  • 📖前端基础
    • HTML
      • 基础知识
      • 进阶知识
      • HTML5
    • CSS
      • 基础知识
      • 进阶知识
      • CSS 专题
        • CSS 选择器
        • CSS 布局
        • CSS 动画
        • CSS 画图
        • 响应式方案
        • CSS BEM 规范
        • CSS 案例
    • JavaScript
      • 基础知识
      • 进阶知识
      • 常用内置对象
        • Array 对象
        • String 对象
        • Number 对象
        • Boolean 对象
        • Math 对象
        • Date 对象
        • RegExp 对象
        • Object 对象
      • JS 专题
        • 数据类型
        • 原型链/继承
        • 对象赋值与拷贝
        • this 的指向
        • 异步操作
        • 模块化
        • 设计模式
    • 浏览器
      • 浏览器模型
      • 事件
      • 位置属性
      • Web 缓存
      • 本地存储
    • 综合内容
      • 前端跨域
      • 登录鉴权
      • 文件上传与下载
  • 🏗️前端框架
    • Vue.js
      • 基础知识
      • Vue 组件通信
      • Vuex 使用指南
      • Vue 动画
      • 静态网站框架 VuePress
    • React.js
      • 基础知识
      • 组件通信
  • 📦计算机基础/后端
    • 图解计算机网络
    • HTTP/HTTPS
    • TCP/UDP
    • Node.js
    • MongoDB
  • 🛠️开发工具
    • 版本控制工具-Git
      • git submodule
    • 构建工具-Webpack
    • 错误监控工具-Sentry
    • 单元测试工具-Jest
    • 包管理工具-NPM
    • 代码编辑器-VSCode
  • 🤔专题内容
    • 前端工程化
    • 代码规范
      • JavaScript 代码规范
      • CSS 代码规范
      • Vue 代码规范
      • Git Commit 规范
      • 代码规范配置
    • 网络安全与防御
    • 性能优化
    • 算法编程
    • 数据可视化
  • 🧑‍💻 面试相关
    • 面试知识总结
    • 面试问题总结
    • 面试常见编程
    • 面试资源汇总
  • 🍭其他
    • 项目经验❗️
    • 踩坑指南❗️
      • JavaScript 踩坑指南
      • CSS 踩坑指南
      • Vue 踩坑指南
    • 学习资源
    • 综合收藏夹
由 GitBook 提供支持
在本页
  • 1. 安装依赖
  • 2. 申请权限
  • 3、项目接入sentry
  • 4、上传sourcemap
  • 4.1 安装依赖
  • 4.2 配置.sentryclirc文件
  • 4.3 配置webpack - vue2.0 + react
  • 4.4 配置webpack - vue3.0
  • 4.5 其他

这有帮助吗?

  1. 开发工具

错误监控工具-Sentry

1. 安装依赖

Vue安装:

npm i @sentry/browser
npm i @sentry/integrations

React安装:

npm i @sentry/react

2. 申请权限

Sentry中配置项目基本信息后,可以得到如下地址明确项目错误信息的上报地址:

https://<key>@report.url.cn/sentry/<project>

3、项目接入sentry

Vue接入:

// /src/index.js
import * as Sentry from '@sentry/browser';
import * as Integrations from '@sentry/integrations';
const RELEASE_VERSION = require('../package.json').version
Sentry.init({
   dsn: "", // 步骤2所得到的地址
   integrations: [
       new Integrations.Vue({
           Vue,
           attachProps: true,
      }),
       new Integrations.RewriteFrames(),
  ],
   release: RELEASE_VERSION, // 版本号
});

React接入:

// /src/index.js
import * as Sentry from '@sentry/react';
const RELEASE_VERSION = require('../package.json').version
Sentry.init({
   dsn: "", // 步骤2所得到的地址
   release: RELEASE_VERSION, // 版本号
});

4、上传sourcemap

4.1 安装依赖

npm i @sentry/webpack-plugin -D

4.2 配置.sentryclirc文件

根目录下创建.sentryclirc文件:

[auth]
token=XXX // sentry中个人的token令牌
​
[defaults]
org=组织名称
project=projectName
url=http://sentry.oa.com/

4.3 配置webpack - vue2.0 + react

// webpack.prod.conf,参数解释详见参考资料
const SentryCliPlugin = require("@sentry/webpack-plugin");
const RELEASE_VERSION = require('../package.json').version
plugins:[
   new SentryCliPlugin({
         include: "./dist",
         release: RELEASE_VERSION,
         configFile: "sentry.properties",
         ignore: ['node_modules', 'webpack.config.js'],
         urlPrefix : "~/", // 正式环境的js的代码路径前缀
  })
]

4.4 配置webpack - vue3.0

// vue.config.js
const SentryPlugin = require("@sentry/webpack-plugin");
const RELEASE_VERSION = require('../package.json').version
module.exports = {
 productionSourceMap: true,
 chainWebpack: config => {
   config.plugin("sentry").use(SentryPlugin, [
    {
       ignore: ["node_modules"],
       include: "./dist", // 上传dist文件的js
       configFile: "./.sentryclirc", // 配置文件地址
       release: RELEASE_VERSION, // 版本号
       urlPrefix: "~/", // 正式环境的js的代码路径前缀
    },
  ]);
},
 // ...
}

@sentry/webpack-plugin在上传后不会删除sourceMap, 修改一下npm run build命令:

"scripts": {
    "build": "vue-cli-service build && rm -fr dist/js/*.map"
}

4.5 其他

webpack-sentry-plugin 可以在上传后删除打包后的sourcemap,可以节省后面上传打包后文件的过滤sourcemap的操作。

npm install webpack-sentry-plugin --save-dev

根目录创建 sentry.config.js

module.exports = {
 organization: '',
 project: '',
 apiKey: '',
};

webpack配置:

const SentryPlugin = require('webpack-sentry-plugin')
const RELEASE_VERSION = require('../package.json').version
plugins: [
 // ...
 new SentryPlugin(Object.assign({
     release: RELEASE_VERSION,
     deleteAfterCompile: true,
     // exclude: /(\.css\.map| \.css | \.html)$/,
     include: /(\.js\.map | \.js)$/, // 只上传js和map文件
     filenameTransform: function (filename) {
       return '~/' + filename
    },
  }, require('../sentry.config.js')))
]
上一页构建工具-Webpack下一页单元测试工具-Jest

最后更新于4年前

这有帮助吗?

参考资料:

如果你对内容有任何疑问,欢迎提交 或

🛠️
vue+sentry 前端异常日志监控
❕issues
✉️ email