---
title: "emitFragment(): function in Emit, TypeShade API reference"
description: "emitFragment, a function in Emit. Emit a ModuleDecl as a WGSL fragment for a host that assembles the final module itself…"
url: https://typeshade.dev/api/emitfragment/
language: en
---

# `emitFragment()`

Function in Emit

Emit a ModuleDecl as a WGSL fragment for a host that assembles the final module itself: the declarations and helper functions without the enable directive header and, unless opts.entryPoints is true, without the stage entry points.

`import { emitFragment } from 'typeshade'`

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

## Syntax

```ts
const emitFragment: (
  m: ModuleDecl,
  opts?: EmitOptions & { entryPoints?: boolean; },
) => EmitFragment
```

## Parameters

**`m` `ModuleDecl`**

**`opts` optional `EmitOptions & { entryPoints?: boolean }`**

## Return value

`EmitFragment`

## Description

Where GLSL would use `#include`, a WGSL host composes by concatenating fragments, so the directives it must place at the top of the module come back in the result’s `preamble` field, and what the fragment declares and requires comes back alongside (see [`EmitFragment`](https://typeshade.dev/api/emitfragment-interface/)).

Prefer this over concatenating [`emitFuncs`](https://typeshade.dev/api/emitfuncs/) and [`emitConst`](https://typeshade.dev/api/emitconst/) output. This function runs the same validation and capability check as [`emitModule`](https://typeshade.dev/api/emitmodule/), so it never writes a module that [`validate`](https://typeshade.dev/api/validate/) or the capability check would have rejected.

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | Writes WGSL for WebGPU. |
| GLSL ES 3.00 (WebGL2) | Does not apply | |
| CPU oracle | Does not apply | |

## In the guide

- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)
- [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/)

## See also

- [`ModuleDecl`](https://typeshade.dev/api/moduledecl/)
- [`EmitFragment`](https://typeshade.dev/api/emitfragment-interface/)
- [`emitFuncs`](https://typeshade.dev/api/emitfuncs/)
- [`emitConst`](https://typeshade.dev/api/emitconst/)
- [`emitModule`](https://typeshade.dev/api/emitmodule/)
- [`validate`](https://typeshade.dev/api/validate/)

## Source

[`src/core/backends/wgsl.ts`, line 253](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/backends/wgsl.ts#L253), at commit af54ddad5
