A zero-dependency Vite plugin that allows importing files (SVG, MD, XML, TXT, or custom extensions) as raw strings at build time. Current stable version is 2.0.3 as of April 2025, requiring Vite >= 6.3.0 (or compatible rolldown-vite) due to hook filter API usage introduced in v2.0.0. It is more lightweight than generic file-loading plugins like rollup-plugin-string or vite-plugin-raw, but limited to string output. TypeScript type declarations are provided via a separate types entry point for automatic module augmentation of default file extensions.
npm install vite-string-pluginVerified import paths — ran on the pinned version, not inferred.
Sets up the plugin to load .svg files as strings and then imports one in a TypeScript module.
Upgrade Vite to 6.3.0 or later, or use vite-string-plugin@1.x (v1.0.5) with Vite < 6.3.0.
Ensure the plugin is added to the Vite plugins array; HMR should work automatically for files matching the pattern. If not, try appending a query parameter like ?raw.
Set match to a broader regex or use Vite's built-in ?raw query for specific files.
Add ambient type declarations for each custom extension as shown in the README.
Use `import { stringPlugin } from 'vite-string-plugin'` instead of `const stringPlugin = require('vite-string-plugin')`.Upgrade Vite to >=6.3.0 or use vite-string-plugin@1.0.5.
Add `"types": ["vite-string-plugin/types"]` to tsconfig.json or create a .d.ts file with declare module statements.