esbuild-raw-loader
Version:
An ESBuild and TSUP plugin that allows importing files as raw text. Useful for loading code files in documentation, interactive demos, or tools like react-live.
43 lines (42 loc) • 1.52 kB
TypeScript
import type { Plugin } from "esbuild";
export interface RawPluginOptions {
/**
* File extensions to check in order of priority if the specified file is missing.
* If it's a directory, the plugin will look for `dir/index.[ext]`.
* @defaultValue ["ts", "tsx", "js", "jsx", "mjs", "mts", "module.css", "module.scss", "css", "scss"]
*/
ext?: string[];
/**
* Custom loader for file processing.
* Overridden by import query suffix (?text, ?base64, etc).
* @defaultValue "text"
*/
loader?: "text" | "base64" | "dataurl" | "file" | "binary" | "default";
/**
* Map file extensions (without dot) to custom loaders.
* Example: { md: "text", png: "dataurl" }
*/
customLoaders?: Record<string, "text" | "base64" | "dataurl" | "file" | "binary" | "default">;
/**
* Plugin name override (for debugging, deduplication, etc.)
*/
name?: string;
/**
* @deprecated Use `customLoaders` instead.
* Previously used to specify extensions to treat as text.
*
* Example replacement:
* ```ts
* customLoaders: { "module.scss": "text", "md": "text" }
* ```
*/
textExtensions?: string[];
}
/**
* ESBuild plugin to enable raw file imports.
*
* This plugin allows importing files with a `?raw` suffix,
* treating them as raw text content. It supports resolving file
* extensions in order of priority and handling custom loaders.
*/
export declare const raw: (options?: RawPluginOptions) => Plugin;