Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/plugin/vite/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Backtrace Configuration
# Replace {universe} and {token} with your actual values from the Backtrace dashboard

# Sourcemap upload URL (used at build time by @backtrace/vite-plugin)
# Project Settings > Symbols > Access tokens
BACKTRACE_UPLOAD_URL=https://submit.backtrace.io/{universe}/{token}/sourcemap

# Error submission URL (used at runtime by @backtrace/browser)
# Note: VITE_ prefix is required for Vite to expose this to client-side code
# Project Settings > Error Submission > Submission tokens
VITE_BACKTRACE_SUBMISSION_URL=https://submit.backtrace.io/{universe}/{token}/json
3 changes: 3 additions & 0 deletions examples/plugin/vite/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
60 changes: 60 additions & 0 deletions examples/plugin/vite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Backtrace Vite Plugin Example

This example demonstrates how to use `@backtrace/vite-plugin` to automatically upload sourcemaps to Backtrace during the Vite build process.

## Setup

1. Install dependencies:
```bash
npm install
```

2. Copy the `.env` file and replace the placeholders with your Backtrace credentials:
```bash
# Edit .env and replace {universe} and {token} with your values
```

## Configuration

Edit the `.env` file with your Backtrace credentials. This example uses two separate URLs:

| Variable | Purpose | Endpoint |
|----------|---------|----------|
| `BACKTRACE_UPLOAD_URL` | Sourcemap upload (build-time) | `.../sourcemap` |
| `VITE_BACKTRACE_SUBMISSION_URL` | Error submission (runtime) | `.../json` |

**Note:** The `VITE_` prefix is required for Vite to expose the variable to client-side code.

You can find your tokens in the Backtrace dashboard under Project Settings > Symbols > Access Tokens (for /sourcemap) and Project Settings > Error Submission > Submission tokens (for /json)

## Usage

Once you've configured your `.env` file:

```bash
# Build with sourcemap upload
npm run build

# Preview the built app
npm run preview
```

The build will:
1. Generate sourcemaps during the build
2. Process the sourcemaps (including source code with `includeSources: true`)
3. Upload them to your Backtrace instance

**Note:** If `BACKTRACE_UPLOAD_URL` contains placeholders or is invalid, the build will complete but sourcemaps won't be uploaded.

## Error Types

This example demonstrates several error submission types:

- **Send an error** - Sends a handled exception with an attachment
- **Send a message** - Sends a simple message/log to Backtrace
- **Send an unhandled exception** - Triggers an unhandled exception
- **Send a promise rejection** - Triggers an unhandled promise rejection

## Vite Version

This example uses Vite 7.1.5. The `@backtrace/vite-plugin` supports Vite versions 4.x through 7.x.
50 changes: 50 additions & 0 deletions examples/plugin/vite/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Backtrace Vite Plugin Example</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="/src/index.css" />
</head>
<body>
<div class="card center">
<a href="https://www.saucelabs.com/">
<img
src="https://info.saucelabs.com/rs/468-XBT-687/images/SL%20logo%20horizontal%20color%2Bdark%402x.png"
width="250"
alt="Sauce Labs"
class="center"
/>
</a>
<br />
<h1 class="card-header">Backtrace Vite Plugin Example</h1>
<p style="text-align: center">Please pick one of the available options:</p>
<br />
<div class="action-container center">
<div class="action-button center">
<a class="text" id="send-error">Send an error</a>
</div>
<div class="action-button center">
<a class="text" id="send-message">Send a message</a>
</div>
<div class="action-button center">
<a class="text" id="send-unhandled-exception">Send an unhandled exception</a>
</div>
<div class="action-button center">
<a class="text" id="send-promise-rejection">Send a promise rejection</a>
</div>
</div>
<div class="summary-information">
<p>If you have any questions or concerns, please contact us at</p>
<a href="mailto:help@saucelabs.com">help@saucelabs.com</a>
<br /><br />
<p>Happy testing,</p>
<p>The Sauce Labs Team</p>
</div>
</div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
Loading