An esbuild plugin that allows importing file contents as raw strings. Version 0.3.0 supports esbuild ^0.14.36 through ^0.25.0. It is a simple, zero-config plugin that attaches to esbuild's resolve and load hooks. Unlike manual readFileSync or similar, it integrates seamlessly with esbuild's build pipeline and respects loaders. Typically used for embedding text files (e.g., shaders, markdown) in bundles. Ships TypeScript declarations.
npm install esbuild-plugin-rawVerified import paths — ran on the pinned version, not inferred.
Shows basic usage: import the plugin, add it to esbuild plugins array, and then import files with ?raw suffix to get their contents as a string.
Append '?raw' to all imports you want as raw strings, e.g., import data from './file.txt?raw'.
Add a declaration file: declare module '*?raw' { const content: string; export default content; }Upgrade esbuild to at least v0.14.36.
Use dynamic import: const RawPlugin = (await import('esbuild-plugin-raw')).default;Run 'npm install -D esbuild-plugin-raw esbuild'
Use default import: import RawPlugin from 'esbuild-plugin-raw';