{"id":22778,"library":"vite-plugin-plain-text","title":"vite-plugin-plain-text","description":"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.","status":"active","version":"1.4.2","language":"javascript","source_language":"en","source_url":"https://github.com/zheeeng/vite-plugin-plain-text","tags":["javascript","vite","plugin","vite-plugin","plain text","typescript"],"install":[{"cmd":"npm install vite-plugin-plain-text","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-plain-text","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-plain-text","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; package provides a default export (function).","wrong":"const plainText = require('vite-plugin-plain-text')","symbol":"default (plugin function)","correct":"import plainText from 'vite-plugin-plain-text'"},{"note":"By default, matched files export a named export 'plainText'. To use default export, set namedExport: false in options.","wrong":"import fileText from './file.text'","symbol":"plainText as named import from matched files","correct":"import { plainText } from './file.text'"},{"note":"Add to vite-env.d.ts for TypeScript projects; alternatively enable dtsAutoGen option for automatic generation.","wrong":"","symbol":"Type declarations (manual)","correct":"declare module '*.text' { export const plainText: string }"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport plainText from 'vite-plugin-plain-text';\n\nexport default defineConfig({\n  plugins: [\n    plainText([/\\/LICENSE$/, '**/*.text', /\\.glsl$/])\n  ]\n});\n\n// src/component.js\nimport { plainText as license } from '../LICENSE';\nimport { plainText as lorem } from '../lorem-ipsum.text';\nimport { plainText as siren } from '../siren.glsl';\n\nconsole.log(license);\nconsole.log(lorem);\nconsole.log(siren);","lang":"typescript","description":"Demonstrates Vite configuration with plainText plugin and importing file contents as strings."},"warnings":[{"fix":"Update imports to use named export 'plainText' or set namedExport: false to get default export.","message":"In v1.2.0, the default export behavior changed: previously matched files used default export; now they use named export 'plainText' by default.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Use namedExport: false explicitly instead of undefined or empty string.","message":"Option 'namedExport' accepts false to enable default export; passing undefined or '' is deprecated and will be removed in future.","severity":"deprecated","affected_versions":">=1.4.0"},{"fix":"Use patterns like '**/*.text' or /\\/LICENSE$/ for reliability.","message":"Glob patterns without leading slash may not match as expected; use absolute-like patterns starting with / or **/ to avoid issues.","severity":"gotcha","affected_versions":"all"},{"fix":"Add generated .d.ts files to .gitignore or use distAutoClean to remove them on startup.","message":"Automatic type declaration generation (dtsAutoGen) creates .d.ts files in the source directory; these may be committed by accident.","severity":"gotcha","affected_versions":">=1.4.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add manual module declarations in vite-env.d.ts or enable dtsAutoGen option.","cause":"TypeScript cannot resolve module types for matched files without declaration files.","error":"Cannot find module './file.text' or its corresponding type declarations."},{"fix":"Change import to use named import: import { plainText } from './LICENSE' or set namedExport: false in plugin options.","cause":"After v1.2.0, matched files export a named export 'plainText' instead of default export.","error":"Uncaught SyntaxError: The requested module './LICENSE' does not provide an export named 'default' (at ...)"},{"fix":"Use default import: import plainText from 'vite-plugin-plain-text'","cause":"Named import from the plugin package itself is incorrect; it exports a default function.","error":"Error: 'plainText' is not exported by node_modules/vite-plugin-plain-text/dist/index.mjs, imported by ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}