https://github.com/unplugin/unplugin-raw
Transform file to a default-export string.
https://github.com/unplugin/unplugin-raw
Last synced: about 1 month ago
JSON representation
Transform file to a default-export string.
- Host: GitHub
- URL: https://github.com/unplugin/unplugin-raw
- Owner: unplugin
- License: mit
- Created: 2023-11-30T02:39:47.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-06-13T22:01:32.000Z (8 months ago)
- Last Synced: 2025-06-13T23:18:04.030Z (8 months ago)
- Language: TypeScript
- Homepage:
- Size: 361 KB
- Stars: 25
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
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
```
Vite
```ts
// vite.config.ts
import Raw from 'unplugin-raw/vite'
export default defineConfig({
plugins: [Raw()],
})
```
Rollup
```ts
// rollup.config.js
import Raw from 'unplugin-raw/rollup'
export default {
plugins: [Raw()],
}
```
Rolldown
```ts
// rolldown.config.js
import Raw from 'unplugin-raw/rolldown'
export default {
plugins: [Raw()],
}
```
esbuild
```ts
// esbuild.config.js
import { build } from 'esbuild'
build({
plugins: [require('unplugin-raw/esbuild')()],
})
```
## 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 doesn't support this syntax)
import text4 from './with.js' with { type: 'text' }
import bytes2 from './with.png' with { type: 'bytes' }
```
## Sponsors
## License
[MIT](./LICENSE) License © 2023-PRESENT [Kevin Deng](https://github.com/sxzz)
[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