Registry / devops / vite-plugin-plain-text

vite-plugin-plain-text

JSON →
library1.4.2jsnpmunverified

A Vite plugin that transforms matched files (e.g., LICENSE, .text, .glsl) into plain text strings, enabling direct import of file contents. Current stable version is 1.4.2, with regular releases. Key features include support for both named and default exports, automatic type declaration generation (.d.ts), sourcemaps, and ESM compatibility. Compared to alternatives like vite-plugin-virtual-plain-text, this plugin operates on real file paths rather than virtual modules.

npm install vite-plugin-plain-text
INSTALL
IMPORT
SIG · VITE-PLUGIN-PLAIN-
V
vite-plugin-plain-text
devopsjavascriptv1.4.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (plugin function)
import plainText from 'vite-plugin-plain-text'
const plainText = require('vite-plugin-plain-text')
ESM-only; package provides a default export (function).
plainText as named import from matched files
import { plainText } from './file.text'
import fileText from './file.text'
By default, matched files export a named export 'plainText'. To use default export, set namedExport: false in options.
Type declarations (manual)
declare module '*.text' { export const plainText: string }
Add to vite-env.d.ts for TypeScript projects; alternatively enable dtsAutoGen option for automatic generation.

Demonstrates Vite configuration with plainText plugin and importing file contents as strings.

// vite.config.ts import { defineConfig } from 'vite'; import plainText from 'vite-plugin-plain-text'; export default defineConfig({ plugins: [ plainText([/\/LICENSE$/, '**/*.text', /\.glsl$/]) ] }); // src/component.js import { plainText as license } from '../LICENSE'; import { plainText as lorem } from '../lorem-ipsum.text'; import { plainText as siren } from '../siren.glsl'; console.log(license); console.log(lorem); console.log(siren);
Debug
Known issues
breakingIn v1.2.0, the default export behavior changed: previously matched files used default export; now they use named export 'plainText' by default.
fix
Update imports to use named export 'plainText' or set namedExport: false to get default export.
affects: >=1.2.0
deprecatedOption 'namedExport' accepts false to enable default export; passing undefined or '' is deprecated and will be removed in future.
fix
Use namedExport: false explicitly instead of undefined or empty string.
affects: >=1.4.0
gotchaGlob patterns without leading slash may not match as expected; use absolute-like patterns starting with / or **/ to avoid issues.
fix
Use patterns like '**/*.text' or /\/LICENSE$/ for reliability.
affects: all
gotchaAutomatic type declaration generation (dtsAutoGen) creates .d.ts files in the source directory; these may be committed by accident.
fix
Add generated .d.ts files to .gitignore or use distAutoClean to remove them on startup.
affects: >=1.4.0
Errors
Common errors & fixes
Cannot find module './file.text' or its corresponding type declarations.
TypeScript cannot resolve module types for matched files without declaration files.
fix
Add manual module declarations in vite-env.d.ts or enable dtsAutoGen option.
Uncaught SyntaxError: The requested module './LICENSE' does not provide an export named 'default' (at ...)
After v1.2.0, matched files export a named export 'plainText' instead of default export.
fix
Change import to use named import: import { plainText } from './LICENSE' or set namedExport: false in plugin options.
Error: 'plainText' is not exported by node_modules/vite-plugin-plain-text/dist/index.mjs, imported by ...
Named import from the plugin package itself is incorrect; it exports a default function.
fix
Use default import: import plainText from 'vite-plugin-plain-text'
Upgrade
Version history
1.4.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources