https://github.com/silverwind/vite-string-plugin
Vite plugin to import files as string, with zero dependencies
https://github.com/silverwind/vite-string-plugin
Last synced: about 2 months ago
JSON representation
Vite plugin to import files as string, with zero dependencies
- Host: GitHub
- URL: https://github.com/silverwind/vite-string-plugin
- Owner: silverwind
- License: bsd-2-clause
- Created: 2023-07-07T22:13:36.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2026-04-10T00:36:04.000Z (2 months ago)
- Last Synced: 2026-04-10T02:40:50.415Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 615 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# vite-string-plugin
[](https://www.npmjs.org/package/vite-string-plugin) [](https://www.npmjs.org/package/vite-string-plugin) [](https://packagephobia.com/result?p=vite-string-plugin)
Vite plugin to import files as string, with zero dependencies
## Usage
#### vite.config.js
```js
import {defineConfig} from "vite";
import {stringPlugin} from "vite-string-plugin";
export default defineConfig({
plugins: [
stringPlugin(),
],
});
```
#### file.js
```js
import foo from "./foo.svg";
```
## Options
- `match`: Regex to match the path against. Default: `/\.(svg|md|xml|txt)$/i`.
## Typescript
If the default file extensions cover your needs, add `vite-string-plugin/types` to your `types` in `tsconfig.json`:
```json
{
"compilerOptions": {
"types": [
"vite-string-plugin/types"
]
}
}
```
Alternatively, you can add ambient type declarations for each file extension:
```ts
declare module "*.svg" {
const value: string;
export default value;
}
declare module "*.md" {
const value: string;
export default value;
}
declare module "*.xml" {
const value: string;
export default value;
}
declare module "*.txt" {
const value: string;
export default value;
}
```
## Related
- [`vite-yaml-plugin`](https://github.com/silverwind/vite-yaml-plugin)