https://github.com/jadedblueeyes/vite-plugin-import-buffer
Vite plugin to import files as node Buffers
https://github.com/jadedblueeyes/vite-plugin-import-buffer
node-buffer vite vite-plugin
Last synced: 4 months ago
JSON representation
Vite plugin to import files as node Buffers
- Host: GitHub
- URL: https://github.com/jadedblueeyes/vite-plugin-import-buffer
- Owner: JadedBlueEyes
- License: mit
- Created: 2025-02-14T16:28:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-10-21T08:12:11.000Z (8 months ago)
- Last Synced: 2026-01-13T07:45:15.964Z (5 months ago)
- Topics: node-buffer, vite, vite-plugin
- Language: TypeScript
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vite-plugin-import-buffer
This vite/rollup plugin allows importing files as node Buffers.
Files are appropriately emitted into build outputs, and loaded as a Buffer automatically.
## Usage
```js
import { defineConfig } from 'vite'
import importBuffer from 'vite-plugin-import-buffer'
export default defineConfig({
plugins: [
importBuffer()
]
})
```
## Example
```js
import fontData from './Inter-Regular.ttf?buffer';
```
## Options
### `include`
Type: `string[] | RegExp`
Default: `[]`
Glob patterns or RegExp to include files.
### `exclude`
Type: `string[] | RegExp`
Default: `[]`
Glob patterns or RegExp to exclude files.
### `loader`
Type: `(src: string) => string`
Default: `(src) => `import { readFile } from 'node:fs/promises';
export const originalUrl = ${src};
const buf = await readFile(new URL(originalUrl, import.meta.url));
export default buf;`
A function that returns the loader code for the buffer.
## License
[MIT](LICENSE)