---
title: "EmitPlugin: interface in Emit, TypeShade API reference"
description: "EmitPlugin, an interface in Emit. A transform that runs inside module emit."
url: https://typeshade.dev/api/emitplugin/
language: en
---

# `EmitPlugin`

Interface in Emit

A transform that runs inside module emit.

`import type { EmitPlugin } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
interface EmitPlugin {
  readonly name: string;
  readonly identity?: string;
  readonly transformIR?: (lowered: ModuleDecl) => ModuleDecl;
  readonly transformText?: (code: string) => string;
}
```

## Description

Plugins are passed to `emitModule` and `emitGlslModule` through [`EmitOptions`](https://typeshade.dev/api/emitoptions/) as `{ plugins: [...] }`. The core emit knows nothing about what a plugin does. The plugins shipped with the package (`mangle`, `minify`, `prune`, `obfuscate` and others) live on the `typeshade/emit-prod` subpath, so an application that emits at runtime and never imports them does not bundle them.

A plugin has two hooks, both optional. `transformIR` receives the module after every lowering and optimisation pass has run, and returns a module the backend can spell into source text. `transformText` receives the assembled source string and returns the string to use in its place.

The hooks fire in stages across all plugins: every plugin’s `transformIR` runs, in `plugins` order, before the module is assembled; then every plugin’s `transformText` runs, in `plugins` order, on the assembled string.

## Examples

### Example

```ts
const banner: EmitPlugin = {
  name: 'banner',
  transformText: (code) => `// generated\n${code}`,
}
const wgsl = emitModule(MODULE, { plugins: [banner] })
```

## Instance properties

**`name` read only `string`**

The plugin’s name, used in error messages and diagnostics.

**`identity` optional read only `string`**

How this plugin appears in the identity string that [`emitIdentity`](https://typeshade.dev/api/emitidentity/) computes for an emit configuration. When it is unset, `name` is used. Set it when the plugin’s own options change the emitted bytes, so that two configurations of the same plugin produce different identities: `minify({a})` and `minify({b})` would otherwise be the same string. None of the plugins shipped with the package set it.

**`transformIR` optional read only `(lowered: ModuleDecl) => ModuleDecl`**

Rewrites the module after every lowering and optimisation pass. The result must be deterministic for a given module: the GLSL vertex and fragment stages are emitted by separate calls that must agree on every shared name.

**`transformText` optional read only `(code: string) => string`**

Rewrites the assembled source string.

## In the guide

- [Production emit](https://typeshade.dev/guide/internals/production-emit/)

## See also

- [`EmitOptions`](https://typeshade.dev/api/emitoptions/)
- [`emitIdentity`](https://typeshade.dev/api/emitidentity/)

## Source

[`src/core/emit.ts`, line 714](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/emit.ts#L714), at commit af54ddad5
