Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tachibana-shin/vite-plugin-arraybuffer
Vite plugin for import file with ArrayBuffer or Uint8Array!
https://github.com/tachibana-shin/vite-plugin-arraybuffer
vite vite-plugin
Last synced: about 1 month ago
JSON representation
Vite plugin for import file with ArrayBuffer or Uint8Array!
- Host: GitHub
- URL: https://github.com/tachibana-shin/vite-plugin-arraybuffer
- Owner: tachibana-shin
- Created: 2023-05-14T16:47:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-18T04:19:49.000Z (3 months ago)
- Last Synced: 2024-11-19T03:41:01.262Z (about 1 month ago)
- Topics: vite, vite-plugin
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/vite-plugin-arraybuffer
- Size: 65.4 KB
- Stars: 14
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
## vite-plugin-arraybuffer
Vite plugin for import file with ArrayBuffer or Uint8Array!
### Install
```bash
pnpm add vite-plugin-arraybuffer -D
```### Usage
vite.config.ts
```ts
import { defineConfig } from "vite";
import arraybuffer from "vite-plugin-arraybuffer";export default defineConfig({
plugins: [arraybuffer()],
});
``````main.ts
import arrayBuffer from "./typescript.svg?arraybuffer";
import uint8array from "./typescript.svg?uint8array";
```Reduce compilation size
This module uses the primitive translation method to `int8` which will double the file size after compilation but it runs very fast because it can be copied directly to RAM.However, for those who want the advantage of packet size there is an additional option called `base64` which will only increase the packet size by `20%` however it will require the browser to decode the base64 before it can be copied. gets into RAM
báe64```main.ts
import arrayBuffer from "./typescript.svg?arraybuffer&base64";
import uint8array from "./typescript.svg?uint8array&base64";
```Thanks [@kevlened](https://github.com/kevlened) for the `base64` support work done by
### TypeScript support
This plugin also supports typing for typescript
tsconfig.json
```json
{
"compilerOptions": {
"types": ["vite-plugin-arraybuffer/types"]
},
"include": ["src"]
}
```