vite sentry 上传sourceMap详细教程
时间: 2023-10-05 07:09:07 浏览: 59
好的,下面是 Vite + Sentry 上传 sourceMap 的详细教程:
1. 在 Sentry 上创建一个项目,并获取你的 DSN。
2. 在 Vite 项目中安装 `@sentry/cli`,可以使用 npm 安装:`npm install --save-dev @sentry/cli`
3. 在 Vite 项目中安装 `@sentry/webpack-plugin`,可以使用 npm 安装:`npm install --save-dev @sentry/webpack-plugin`
4. 在 Vite 项目的根目录下创建一个 `sentry.properties` 文件,并写入如下内容:
```
defaults.url=https://sentry.io/
defaults.org=your-org-name
defaults.project=your-project-name
auth.token=your-auth-token
```
其中,`your-org-name`、`your-project-name` 和 `your-auth-token` 需要替换成你自己 Sentry 项目的组织名、项目名和认证 token。
5. 在 Vite 项目的 `vite.config.js` 文件中添加以下代码:
```javascript
const SentryWebpackPlugin = require('@sentry/webpack-plugin');
const { sentryDsn, release, sentryOrg, sentryProject } = require('./sentry.config');
module.exports = {
// ...其他配置
plugins: [
// ...其他插件
new SentryWebpackPlugin({
include: './dist',
ignore: ['node_modules'],
configFile: 'sentry.properties',
release: release,
urlPrefix: '~/',
deploy: {
env: 'production',
name: 'your-deploy-name',
url: 'your-deploy-url',
},
dryRun: false,
authToken: process.env.SENTRY_AUTH_TOKEN,
org: sentryOrg,
project: sentryProject,
setCommits: {
auto: true,
},
})
],
build: {
sourcemap: true
}
};
```
其中,`sentry.config.js` 文件可以自行创建,并写入以下内容:
```javascript
module.exports = {
sentryDsn: 'your-sentry-dsn',
release: process.env.RELEASE_VERSION,
sentryOrg: 'your-sentry-org',
sentryProject: 'your-sentry-project',
};
```
需要将 `your-sentry-dsn`、`your-sentry-org` 和 `your-sentry-project` 替换成你自己 Sentry 项目的 DSN、组织名和项目名。`process.env.RELEASE_VERSION` 表示你的代码版本号,可以在部署时设置。
6. 在部署时设置 `RELEASE_VERSION` 环境变量,例如:
```bash
RELEASE_VERSION=v1.0.0 npm run build
```
7. 执行 `npm run build` 命令来构建你的项目,并上传 sourcemap 文件到 Sentry。上传成功后,你就可以在 Sentry 上看到你的代码的源码以及调用栈等信息了。
希望这些步骤能够帮助到你。