{"id":26597,"library":"vite-plugin-raw","title":"vite-plugin-raw","description":"Transforms any file type (e.g., SVG, CSS, text) into an imported string in Vite. Currently at version 1.0.3, stable but minimal maintenance. Differentiates from raw-loader or ?raw suffix by offering a plugin-based approach with regex match and exclude patterns, allowing selective file transformation without query strings.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/xingw-z/vite-plugin-raw","tags":["javascript","vite","raw"],"install":[{"cmd":"npm install vite-plugin-raw","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-raw","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-raw","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM default import is preferred; CJS require also works.","wrong":"const vitePluginRaw = require('vite-plugin-raw')","symbol":"default","correct":"import vitePluginRaw from 'vite-plugin-raw'"},{"note":"This package has a default export, not a named export.","wrong":"import { vitePluginRaw } from 'vite-plugin-raw'","symbol":"default","correct":"const vitePluginRaw = require('vite-plugin-raw')"},{"note":"Common misconception: the exported function is named vitePluginRaw.","wrong":"import { raw } from 'vite-plugin-raw'","symbol":"vitePluginRaw","correct":"import vitePluginRaw from 'vite-plugin-raw'"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport vitePluginRaw from 'vite-plugin-raw';\n\nexport default defineConfig({\n  plugins: [\n    vitePluginRaw({\n      match: /\\.svg$/,\n      exclude: [new RegExp('node_modules')]\n    })\n  ]\n});\n\n// main.js\nimport svgContent from './icon.svg';\nconsole.log(svgContent); // string\n","lang":"javascript","description":"Configure vite-plugin-raw to import SVG files as strings, excluding node_modules."},"warnings":[{"fix":"Use specific regex like /\\.(svg|txt)$/ and add exclude patterns for directories.","message":"match regex must be correctly scoped; overly broad patterns may transform unwanted files.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use path.resolve(__dirname, 'dir') for exclude entries.","message":"Exclude paths must be absolute or regex; relative paths may not work.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use static import statements for transformed files.","message":"Only transforms files imported via ES modules; dynamic imports may not work.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `import vitePluginRaw from 'vite-plugin-raw'`","cause":"Using named import instead of default import.","error":"TypeError: vitePluginRaw is not a function"},{"fix":"Run `npm install -D vite-plugin-raw`","cause":"Package not installed or missing from devDependencies.","error":"ERR_MODULE_NOT_FOUND: Cannot find package 'vite-plugin-raw'"},{"fix":"Check that the plugin is added to Vite config and match regex covers .svg.","cause":"vite-plugin-raw not configured or not transforming that file.","error":"The requested module '...icon.svg' does not provide an export named 'default'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}