# unplugin-raw

> Transform file to a default-export string.

Latest version **0.8.0** (published 2026-08-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install unplugin-raw
pnpm add unplugin-raw
yarn add unplugin-raw
bun add unplugin-raw
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.8.0 |
| Published | 2026-08-31 |
| First published | 2023-11-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^22.18.0 \|\| ^24.11.0 \|\| >=26.0.0 |
| Dependencies | 2 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 37 |
| Author | Kevin Deng <sxzz@sxzz.moe> |
| Maintainers | userquin, antfu, sxzz, hannoeru |
| Keywords | unplugin, rollup, vite, esbuild, webpack |

## Links

- npm: https://www.npmjs.com/package/unplugin-raw
- Repository: https://github.com/unplugin/unplugin-raw
- Homepage: https://github.com/unplugin/unplugin-raw#readme
- Issues: https://github.com/unplugin/unplugin-raw/issues
- Funding: https://github.com/sponsors/sxzz
- npm.io page: https://npm.io/package/unplugin-raw

## Dependencies (2)

- [unplugin](https://npm.io/package/unplugin.md) ^3.3.0
- [unplugin-utils](https://npm.io/package/unplugin-utils.md) ^0.3.2

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 0.8.0 (latest) — 2026-08-31
- 0.7.0 — 2026-03-28
- 0.6.4 — 2026-01-05
- 0.6.3 — 2025-09-20
- 0.6.2 — 2025-09-16
- 0.6.1 — 2025-08-24
- 0.6.0 — 2025-08-13
- 0.5.1 — 2025-08-04
- 0.5.0 — 2025-05-09
- 0.4.5 — 2025-04-09
- 0.4.4 — 2025-03-05
- 0.4.3 — 2025-02-25
- 0.4.2 — 2025-02-06
- 0.4.1 — 2025-02-05
- 0.4.0 — 2025-02-04
- … 8 more at https://npm.io/package/unplugin-raw/versions

## README

# unplugin-raw

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Unit Test][unit-test-src]][unit-test-href]

Transform file to a default-export string, and can be transformed by esbuild.

## Installation

```bash
npm i -D unplugin-raw

npm i -D esbuild # Optional, if you want to transform TypeScript to JavaScript
```

<details>
<summary>Vite</summary><br>

```ts
// vite.config.ts
import Raw from 'unplugin-raw/vite'

export default defineConfig({
  plugins: [Raw()],
})
```

<br></details>

<details>
<summary>Rollup</summary><br>

```ts
// rollup.config.js
import Raw from 'unplugin-raw/rollup'

export default {
  plugins: [Raw()],
}
```

<br></details>

<details>
<summary>Rolldown</summary><br>

```ts
// rolldown.config.js
import Raw from 'unplugin-raw/rolldown'

export default {
  plugins: [Raw()],
}
```

<br></details>

<details>
<summary>esbuild</summary><br>

```ts
// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [require('unplugin-raw/esbuild')()],
})
```

<br></details>

## Options

```ts
export interface TransformOptions {
  /** @default [/\.[cm]?[jt]sx?$/] */
  include?: FilterPattern
  /** @default [/node_modules/] */
  exclude?: FilterPattern
  /** @default {} */
  options?: EsbuildTransformOptions
}

export interface Options {
  /** @default 'pre' */
  enforce?: 'pre' | 'post' | undefined
  /**
   * Transform
   * @default false
   */
  transform?: TransformOptions | boolean
}
```

## Usage

```ts
import text from './js.js?raw'
import text2 from './jsx.jsx?raw'
import bytes from './png.png?bytes'
import text3 from './ts.ts?raw'
// Import attributes (Rolldown and Vite 8+ doesn't support this syntax)
import text4 from './with.js' with { type: 'text' }
import bytes2 from './with.png' with { type: 'bytes' }
```

## Sponsors

<p align="center">
  <a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
    <img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
  </a>
</p>

## License

[MIT](./LICENSE) License © 2023-PRESENT [Kevin Deng](https://github.com/sxzz)

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/unplugin-raw.svg
[npm-version-href]: https://npmjs.com/package/unplugin-raw
[npm-downloads-src]: https://img.shields.io/npm/dm/unplugin-raw
[npm-downloads-href]: https://www.npmcharts.com/compare/unplugin-raw?interval=30
[unit-test-src]: https://github.com/unplugin/unplugin-raw/actions/workflows/unit-test.yml/badge.svg
[unit-test-href]: https://github.com/unplugin/unplugin-raw/actions/workflows/unit-test.yml

---
_Source: https://npm.io/package/unplugin-raw · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
