Skip to content

Commit

Permalink
Merge pull request #2 from kricsleo/feature/auto-soucemap
Browse files Browse the repository at this point in the history
Feature/auto soucemap
  • Loading branch information
kricsleo authored Nov 12, 2022
2 parents 24c3efd + 9372a89 commit 35ede52
Show file tree
Hide file tree
Showing 14 changed files with 859 additions and 7,637 deletions.
132 changes: 125 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

Sentry plugin for webpack, vite, rollup, nuxt .ect.

It's used to upload sourcemap or release your project to Sentry ([What's Sentry?](https://sentry.io/welcome/)).

You might also refer official plugin: [@sentry/webpack-plugin](https://github.com/getsentry/sentry-webpack-plugin), but it's just for webpack. Besides, this one-in-all plugin provides more useful features.

## Features

- 📦 Supports multiple bundlers and frameworks, including webpack, vite, rollup, nuxt and so on.
- ✨ Auto-detect configs depending on current environment.
- 🧹 Auto clean local soucemap files after upload (For security).
- 🍬 Optional runtime provided, easy to init Sentry at runtime.

## Install

```bash
Expand All @@ -24,7 +35,7 @@ export default defineConfig({
})
```

Example: [`playground/`](./playground/vite)
Example: [`playground/vite`](./playground/vite)

<br></details>

Expand All @@ -42,7 +53,7 @@ export default {
}
```

Example: [`playground/`](./playground/rollup)
Example: [`playground/rollup`](./playground/rollup)

<br></details>

Expand All @@ -60,7 +71,7 @@ module.exports = {
}
```

Example: [`playground/`](./playground/webpack)
Example: [`playground/webpack`](./playground/webpack)

> This module works for Webpack >= 3
Expand All @@ -78,7 +89,7 @@ export default {
}
```

Example: [`playground/`](./playground/nuxt)
Example: [`playground/nuxt`](./playground/nuxt)

> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
Expand All @@ -103,7 +114,8 @@ module.exports = {
<details>
<summary>esbuild</summary><br>

Haven't tested it yet.
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 👂. )

<br></details>

Expand Down Expand Up @@ -145,6 +157,112 @@ For TS support, add the following config to your `tsconfig.json`:
}
```

## Thanks
## Options

Much like [@sentry/webpack-plugin](https://github.com/getsentry/sentry-webpack-plugin), but provides more options.

[vite-plugin-sentry](https://github.com/ikenfin/vite-plugin-sentry)
| Option | Type | Required | Default | Description |
| -------- | -------- | -------- | ------- |-------------------------------------------------------------------------------- |
| cleanLocal | `boolean` | optional | `true` | Delete local sourcemap files after uploaded to Sentry. |
| publish | `boolean` | optional | `false` | If publish project to Sentry(Release, deploy, upload sourcemap and so on.). |


```ts
import type { SentryCliCommitsOptions, SentryCliNewDeployOptions, SentryCliOptions, SentryCliUploadSourceMapsOptions } from '@sentry/cli'

/** options */
export interface Options extends SentryCliOptions {
/**
* The URL of the Sentry
*/
url: string
/**
* Orgination name in Sentry
*/
org: string
/**
* Project name in Senrty
*/
project: string
/**
* Auth token
*/
authToken: string
/**
* Release version,
* auto generated by commit hash,
* you can also config it by yourself
*/
release?: string
/**
* If use short commit hash for release version
* @default true
*/
shortRelease?: boolean
/**
* If publish project,
* means upload soucemap and record deploy info .etc.
* You might want to turn it on when deploying but not locally developing
* @default false
*/
publish?: boolean
/**
* Sourcemap configs
*/
sourcemap?: SourcemapOptions
/**
* Deploy configs
*/
deploy?: DeployOptions
/**
* If delete local sourcemap after the publish,
* @default true
*/
cleanLocal?: boolean
/**
* If Remove all previous artifacts in the same release.
* @default false
*/
cleanArtifacts?: boolean
/**
* If finalize a release after the publish
* @default true
*/
finalize?: boolean
/**
* Path of config file
*/
configFile?: string
/**
* Commits configs
*/
commits?: SentryCliCommitsOptions
/**
* If attempts a dry run.
* Usually used for debugging which mocks the publish work
* @default false
*/
dryRun?: boolean
}

export interface SourcemapOptions extends Omit<SentryCliUploadSourceMapsOptions, 'include'> {
/**
* Sourcemap paths
* Auto-detect(You can provide it when it's wrong)
*/
include?: SentryCliUploadSourceMapsOptions['include']
/**
* !IMPORTANT!: MUST START WITH `~/` if you don't want to set the domain
* Auto-detect(You can provide it when it's wrong)
*/
urlPrefix?: SentryCliUploadSourceMapsOptions['urlPrefix']
}

export interface DeployOptions extends Omit<SentryCliNewDeployOptions, 'env'> {
/**
* Environment
* Auto-detect and use "process.env.NODE_ENV" as fallback
*/
env?: SentryCliNewDeployOptions['env']
}
```
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@
"dependencies": {
"@sentry/cli": "^2.7.0",
"rimraf": "^3.0.2",
"unplugin": "^0.9.6",
"webpack-virtual-modules": "^0.4.6"
"unplugin": "^0.10.2"
},
"devDependencies": {
"@antfu/eslint-config": "^0.27.0",
Expand Down
23 changes: 1 addition & 22 deletions playground/nuxt/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ export default {
]
},

// Global CSS: https://go.nuxtjs.dev/config-css
css: [
],

// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
],

// Auto import components: https://go.nuxtjs.dev/config-components
components: true,

// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/typescript
Expand All @@ -38,18 +27,8 @@ export default {
project: 'demo',
authToken: 'xxxxxx',
publish: true,
cleanLocal: false,
dryRun: true,
}]
],

// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
extend(config) {
config.devtool = 'hidden-source-map';
},
},

// Modules: https://go.nuxtjs.dev/config-modules
modules: [
],
}
3 changes: 2 additions & 1 deletion playground/rollup/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
input: 'src/index.js',
output: {
format: 'iife',
sourcemap: true,
sourcemap: 'hidden',
dir: 'dist',
},
plugins: [
Expand All @@ -18,6 +18,7 @@ export default {
project: 'demo',
authToken: 'xxxxxx',
publish: production,
cleanLocal: false,
dryRun: true,
}),
],
Expand Down
4 changes: 1 addition & 3 deletions playground/vite/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ export default defineConfig({
project: 'demo',
authToken: 'xxxxxx',
publish: process.env.NODE_ENV === 'production',
cleanLocal: false,
dryRun: true,
}),
],
build: {
sourcemap: true,
},
server: {
open: true
}
Expand Down
Loading

0 comments on commit 35ede52

Please sign in to comment.