Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kricsleo/unplugin-sentry
๐ช All-in-one plugin for sentry, support webpack & vite & rollup & nuxt.
https://github.com/kricsleo/unplugin-sentry
plugin rollup sentry vite webpack
Last synced: 24 days ago
JSON representation
๐ช All-in-one plugin for sentry, support webpack & vite & rollup & nuxt.
- Host: GitHub
- URL: https://github.com/kricsleo/unplugin-sentry
- Owner: kricsleo
- License: mit
- Created: 2022-10-09T11:09:13.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T04:10:47.000Z (10 months ago)
- Last Synced: 2024-04-24T18:55:30.196Z (7 months ago)
- Topics: plugin, rollup, sentry, vite, webpack
- Language: TypeScript
- Homepage:
- Size: 689 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
unplugin-sentry
All-in-one plugin for Sentry, supports webpack, vite, rollup, nuxt .ect.
It's used to upload sourcemap and release your project to Sentry ([What's Sentry?](https://sentry.io/welcome/)).## Features
- ๐ช Supports multiple bundlers and frameworks - including webpack, vite, rollup, nuxt and so on.
- โจ Auto-detect configs depending on current environment - config as less as you need
- ๐งน Auto clean local soucemap files after upload (For security) - both `*.js.map` and `*.css.map`.
- ๐ฌ Optional runtime provided - easy to init Sentry at runtime.## Install
```bash
npm i unplugin-sentry -D
```Vite
```ts
// vite.config.ts
import unpluginSentry from 'unplugin-sentry/vite'export default defineConfig({
plugins: [
unpluginSentry({ /* options */ }),
],
})
```Example: [`playground/vite`](./playground/vite)
Rollup
```ts
// rollup.config.js
import unpluginSentry from 'unplugin-sentry/rollup'export default {
plugins: [
unpluginSentry({ /* options */ }),
],
}
```Example: [`playground/rollup`](./playground/rollup)
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-sentry/webpack')({ /* options */ })
]
}
```Example: [`playground/webpack`](./playground/webpack)
> This module works for Webpack >= 3
Nuxt
```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-sentry/nuxt', { /* options */ }],
],
}
```Example: [`playground/nuxt`](./playground/nuxt)
> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-sentry/webpack')({ /* options */ }),
],
},
}
```
esbuild
I don't use esbuild for now, so it haven't been tested in esbuild yet.
(You can have a try and tell me if it works ๐. )
## Runtime Support
Besides uploading sourcemap to Sentry and other publishing works, this plugin also injects a virtual module named `virtual-unplugin-sentry-runtime` into your project.
It provides some useful meta info when initing Sentry at runtime. For example, when you call `Sentry.init({/** options **/})`, the `environment` and `release` options must match the one you use when uploading sourcemap. So that when debugging the issue in Sentry, the sourcemap can be correctly mapped.
```ts
import * as sentryMeta from 'virtual-unplugin-sentry-runtime'console.log(sentryMeta)
// {
// ORG: string
// PROJECT: string
// ENV: string
// RELEASE: string
// DIST: string
// PUBLISH: boolean
// }
```Need TS support for this runtime module? Just add the following config to your `tsconfig.json`.
```json
{
"compilerOptions": {
"types": ["unplugin-sentry/runtime"]
}
}
```## Options
Extends from [@sentry/cli - SentryCliOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L5).
| Prop | Type | Required | Default | Description |
|-----------------|-----------|----------|---------|------------------------------------------------------------------------------------------------------------------------|
| url | `string` | โ | `https://sentry.io/` | The URL of the Sentry instance you are connecting to.
This value will update `SENTRY_URL env variable. |
| org | `string` | โ | - | Organization slug.
This value will update `SENTRY_ORG` env variable. |
| project | `string` | โ | - | Project Project slug.
This value will update `SENTRY_PROJECT` env variable. |
| authToken | `string` | โ | - | Authentication token for API, interchangeable with apiKey.
This value will update `SENTRY_AUTH_TOKEN` env variable. |
| publish | `boolean` | โ | `false` | If publish project to Sentry.
Means to upload soucemap files and release the version to Sentry server.
You might want to turn it on only when deploying projects other than locally developing.
| release | `string` | โ | - | Release version.
Automatically generated from commit hash value if not provided. |
| shortRelease | `boolean` | โ | `true` | If use short commit hash for automatically generated release version. |
| cleanLocal | `boolean` | โ | `true` | If remove local sourcemap files (`*.js.map` & `*.css.map`) after the publish. |
| cleanArtifacts | `boolean` | โ | `false` | If remove previous artifacts in the same release. |
| sourcemap | [`SourcemapOptions`](#sourcemapoptions) | โ | - | Sourcemap options. |
| deploy | [`DeployOptions`](#deployoptions) | โ | - | Deploy options. |
| commits | [`CommitsOptions`](#commitsoptions) | โ | - | Commits options. |
| finalize | `boolean` | โ | `true` | If finalize a release after the publish. |
| silent | `boolean` | โ | `false` | If true, all logs are suppressed. |
| dryRun | `boolean` | โ | `false` | If attempts a dry run.
Usually used for debugging which mocks publishing. |
| configFile | `string` | โ | - | Path of Sentry config file. |#### SourcemapOptions
Extends from [@sentry/cli - SentryCliUploadSourceMapsOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L64).
| Prop | Type | Required | Default | Description |
|----------------------|------------------|----------|-------------|----------------------------------------------------------------------------------------------------|
| include | `Array` | โ | -
Auto-detectd from current bundler(webpack, vite, rollup and so on). | One or more paths that Sentry CLI should scan recursively for sources.
It will upload all .map files and match associated .js files.
`type SourceMapsPathDescriptor = Omit & { paths: string[] }` |
| urlPrefix | `string` | โ | -
Auto-detectd from current bundler(webpack, vite, rollup and so on). | This sets an URL prefix at the beginning of all files.
This is also useful if your files are stored in a sub folder. **BUT REMEMBER TO START WITH `~/`.** eg: url-prefix `~/static/js`. |
| urlSuffix | `string` | โ | - | This sets an URL suffix at the end of all files.
Useful for appending query parameters. |
| ignore | `string[]` | โ | - | One or more paths to ignore during upload. Overrides entries in ignoreFile file. |
| ignoreFile | `string` \| `null` | โ | - | Path to a file containing list of files/directories to ignore.
Can point to .gitignore or anything with same format. |
| dist | `string` | โ | - | Unique identifier for the distribution, used to further segment your release.
Usually your build number.
| rewrite | `boolean` | โ | `true` | Enables rewriting of matching sourcemaps so that indexed maps are flattened and missing sources are inlined if possible. |
| sourceMapReference | `boolean` | โ | - | This prevents the automatic detection of sourcemap references. |
| stripPrefix | `string[]` | โ | - | When paired with the rewrite option this will remove a prefix from uploaded files.
For instance you can use this to remove a path that is build machine specific. |
| stripCommonPrefix | `boolean` | โ | - | When paired with the rewrite option this will add ~ to the stripPrefix array. |
| validate | `boolean` | โ | - | This attempts sourcemap validation before upload when rewriting is not enabled.
It will spot a variety of issues with source maps and cancel the upload if any are found.
This is not enabled by default as this can cause false positives. |
| ext | `string[]` | โ | - | This sets the file extensions to be considered. By default the following file extensions are processed: js, map, jsbundle and bundle. |#### DeployOptions
Extends from [@sentry/cli - SentryCliNewDeployOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L126).
| Prop | Type | Required | Default | Description |
|-----------|-----------|----------|---------|-------------------------------------------------------------------------------------------------------------------|
| env | `string` | โ | -
Auto-detectd from current bundler(webpack, vite, rollup and so on) and use "process.env.NODE_ENV" as fallback. | Environment for this release. Values that make sense here would be `production` or `staging`. |
| started | `number` \| `string` | โ | - | Deployment start time in Unix timestamp (in seconds) or ISO 8601 format. |
| finished | `number` \| `string` | โ | - | Deployment finish time in Unix timestamp (in seconds) or ISO 8601 format. |
| time | `number` | โ | - | Deployment duration (in seconds). Can be used instead of started and finished. |
| name | `string` | โ | - | Human readable name for the deployment. |
| url | `string` | โ | - | URL that points to the deployment. |#### CommitsOptions
Extends from [@sentry/cli - SentryCliCommitsOptions](https://github.com/getsentry/sentry-cli/blob/master/js/index.d.ts#L153).
| Prop | Type | Required | Default | Description |
|-----------------|-----------|----------|---------|--------------------------------------------------------------------------------------------------------------------|
| auto | `boolean` | โ | - | Automatically choose the associated commit (uses the current commit). Overrides other setCommit options. |
| repo | `string` | โ | - | The full repo name as defined in Sentry. Required if auto option is not true. |
| commit | `string` | โ | - | The current (last) commit in the release. Required if auto option is not true. |
| previousCommit | `string` | โ | - | The commit before the beginning of this release.
If omitted, this will default to the last commit of the previous release in Sentry.
If there was no previous release, the last 10 commits will be used. |
| ignoreMissing | `boolean` | โ | - | When the flag is set and the previous release commit was not found in the repository, will create a release.
with the default commits count(or the one specified with `--initial-depth`) instead of failing the command. |
| ignoreEmpty | `boolean` | โ | - | When the flag is set, command will not fail and just exit silently if no new commits for a given release are found.|## License
[MIT](./LICENSE) License ยฉ 2021-Present [kricsleo](https://github.com/kricsleo)