> ## Documentation Index
> Fetch the complete documentation index at: https://docs.appsignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# @appsignal/webpack

> Upload private sourcemaps to AppSignal during a webpack build with the @appsignal/webpack plugin.

The `@appsignal/webpack` plugin uploads [private sourcemaps](https://docs.appsignal.com/front-end/sourcemaps.md#private-sourcemaps) during your webpack build. AppSignal uses the sourcemaps to map error backtraces from compiled JavaScript to your original source code.

The plugin supports webpack 4 and 5.

> [!WARNING]
>
> The webpack plugin is in beta. Report bugs in the [AppSignal for JavaScript issue tracker](https://github.com/appsignal/appsignal-javascript/issues).

## Install the plugin

Install `@appsignal/webpack`:

```sh npm theme={null}
npm install @appsignal/webpack
```

```sh yarn theme={null}
yarn add @appsignal/webpack
```

## Configure webpack

> [!NOTE]
>
> Add `AppsignalPlugin` and enable sourcemap generation only in your production webpack configuration. This avoids generating and uploading sourcemaps on every development build.

This example uses an ES module configuration file, `webpack.config.mjs`.

```js JavaScript theme={null}
import { AppsignalPlugin } from "@appsignal/webpack";

export default {
  mode: "production",
  devtool: "source-map",
  plugins: [
    new AppsignalPlugin({
      apiKey: process.env.APPSIGNAL_PUSH_API_KEY,
      release: process.env.REVISION,
      appName: process.env.APPSIGNAL_APP_NAME,
      environment: "<your environment>",
      urlRoot: "https://example.com/assets",
    }),
  ],
};
```

Provide these variables in your build environment:

* `APPSIGNAL_PUSH_API_KEY` holds your Push API key. Store it as a secret and keep it out of source control and the front-end bundle.
* `APPSIGNAL_APP_NAME` matches the app name shown in AppSignal.
* `REVISION` matches the [`revision` option](https://docs.appsignal.com/front-end/configuration/options#revision) in your AppSignal for JavaScript configuration.

Set `urlRoot` to the public URL of webpack's `output.path`. The plugin appends each sourcemap's path relative to `output.path` to `urlRoot` and removes the `.map` suffix. For example, if `output.filename` is `"js/[name].js"` and webpack emits `js/main.js.map`, the example registers it for `https://example.com/assets/js/main.js`. **Do not** add the `js/` subdirectory to `urlRoot`, or the URL becomes `https://example.com/assets/js/js/main.js`, which will not match the backtrace.

When webpack emits the build files, the plugin uploads each file whose name ends in `.map` to AppSignal.

## Options

| Option | Requirement | Description |
| - | - | - |
| `apiKey` | Required | An organization-level or app-level [Push API key](https://docs.appsignal.com/appsignal/terminology.md#push-api-key), not a Front-end API key. |
| `release` | Required | The revision for this build. It must match the `revision` in your AppSignal for JavaScript configuration. |
| `appName` | Required | The app name in AppSignal. |
| `urlRoot` | Required | The public URL of webpack's `output.path`, or an array of URLs. |
| `environment` | Required in TypeScript | The app environment. Set it explicitly because `NODE_ENV` may not be set. At runtime, the plugin defaults to `NODE_ENV` or `development` if unset. |
| `deleteAfterCompile` | Optional | Set to `true` to delete `.map` files from the build output after compilation. |
| `timeout` | Optional | The upload timeout in milliseconds. Defaults to `5000`. |
| `endpoint` | Optional | The sourcemaps API base URL. Defaults to `https://appsignal.com/api`. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.