> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# SourceMapDevToolPlugin

This plugin enables more fine grained control of source map generation. It is also enabled automatically by certain settings of the [`devtool`](/config/devtool.md) configuration option.

## Examples

The following examples demonstrate some common use cases for this plugin.

### Basic use case

You can use the following code to replace the configuration option devtool: inline-source-map with an equivalent custom plugin configuration:

```js title="rspack.config.mjs"
import { rspack } from '@rspack/core';

export default {
  devtool: false,
  plugins: [new rspack.SourceMapDevToolPlugin({})],
};
```

### Exclude vendor maps

The following code excludes the `vendor.js` output asset from source map generation:

```js
new rspack.SourceMapDevToolPlugin({
  filename: '[file].map[query]',
  exclude: ['vendor.js'],
});
```

### Host source maps externally

Set a URL for source maps. Useful for hosting them on a host that requires authorization.

```js
new rspack.SourceMapDevToolPlugin({
  append: '\n//# sourceMappingURL=https://example.com/sourcemap/[url]',
  filename: '[file].map[query]',
});
```

And for cases when source maps are stored in the upper level directory:

```
project
|- dist
  |- public
    |- bundle-[hash].js
  |- sourcemaps
    |- bundle-[hash].js.map
```

With the following config:

```js
new rspack.SourceMapDevToolPlugin({
  filename: 'sourcemaps/[file].map',
  publicPath: 'https://example.com/project/',
  fileContext: 'public',
});
```

Will produce the following URL:

```
https://example.com/project/sourcemaps/bundle-[hash].js.map
```

## Options

### test

- **Type:** `string` `RegExp` `[string, RegExp]`

Select output assets for source map generation by matching their emitted filenames. When omitted, `test` does not filter output assets.

### include

- **Type:** `string` `RegExp` `[string, RegExp]`

Include source maps for output assets whose emitted filenames match the given value.

### exclude

- **Type:** `string` `RegExp` `[string, RegExp]`

Exclude output assets whose emitted filenames match the given value from source map generation.

`test`, `include`, and `exclude` match output asset filenames, such as `vendor.js`, rather than source module paths, such as `src/index.js` or `node_modules/package/index.js`.

### filename

- **Type:** string

Defines the output filename of the SourceMap (will be inlined if no value is provided).

### append

- **Type:** `string` `function`

Appends the given value to the original asset. Usually the `#sourceMappingURL` comment. `[url]` is replaced with a URL to the source map file. Path parameters are supported: `[chunk]`, `[filename]` and `[contenthash]`. Setting append to false disables the appending.

### moduleFilenameTemplate

- **Type:** `string`

See [`output.devtoolModuleFilenameTemplate`](/config/output.md#outputdevtoolmodulefilenametemplate).

### fallbackModuleFilenameTemplate

- **Type:** `string`

See link above.

### namespace

- **Type:** `string`

See [`output.devtoolNamespace`](/config/output.md#outputdevtoolnamespace).

### module

- **Type:** `boolean`
- **Default:** `true`

Indicates whether loaders should generate source maps.

### columns

- **Type:** `boolean`
- **Default:** `true`

Indicates whether column mappings should be used.

### noSources

- **Type:** `boolean`
- **Default:** `false`

Prevents the source file content from being included in the source map.

### publicPath

- **Type:** `string`

Emits absolute URLs with public path prefix, e.g. `https://example.com/project/`.

### fileContext

- **Type:** `string`

Makes the `[file]` argument relative to this directory.

The `fileContext` option is useful when you want to store source maps in an upper level directory to avoid `../../` appearing in the absolute `[url]`.

### sourceRoot

- **Type:** `string`

Provide a custom value for the `sourceRoot` property in the SourceMap.

:::tip
Setting `module` and/or `columns` to `false` will yield less accurate source maps but will also improve compilation performance significantly.
:::

:::tip
If you want to use a custom configuration for this plugin in [development mode](/config/mode.md#development), make sure to disable the default one. I.e. set `devtool: false`.
:::


This page is adapted from [webpack documentation](https://webpack.js.org/plugins/source-map-dev-tool-plugin/) under the [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), with modifications.

