{"id":22906,"library":"vite-plugin-utils","title":"vite-plugin-utils","description":"vite-plugin-utils is a collection of opinionated utility functions for Vite plugin development. It provides constants, helper functions, and plugin sorting utilities to streamline plugin creation. Currently at version 0.4.5 with monthly releases, it focuses on reducing boilerplate for Vite plugin authors. Unlike general Vite utilities like unplugin or vite-plugin-inspect, this package offers specific sorted plugin handling and module-related constants. The package is ESM-only, designed for Vite 4+, and includes TypeScript declarations. Its lightweight API covers common patterns like virtual module IDs and plugin ordering.","status":"active","version":"0.4.5","language":"javascript","source_language":"en","source_url":"https://github.com/vite-plugin/vite-plugin-utils","tags":["javascript","vite","plugin","utils"],"install":[{"cmd":"npm install vite-plugin-utils","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-utils","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugins require Vite's plugin API types and runtime.","package":"vite","optional":true}],"imports":[{"note":"Package is ESM-only. CommonJS require will fail.","wrong":"const resolveVitePluginUtils = require('vite-plugin-utils')","symbol":"resolveVitePluginUtils","correct":"import { resolveVitePluginUtils } from 'vite-plugin-utils'"},{"note":"Subpath export 'constant' is accessed via '/constant' suffix, not root.","wrong":"import { VIRTUAL_MODULE_PREFIX } from 'vite-plugin-utils'","symbol":"constant","correct":"import { VIRTUAL_MODULE_PREFIX } from 'vite-plugin-utils/constant'"},{"note":"This utility is available under the '/sort-plugin' subpath.","wrong":"import { sortPlugin } from 'vite-plugin-utils'","symbol":"sortPlugin","correct":"import { sortPlugin } from 'vite-plugin-utils/sort-plugin'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport { sortPlugin } from 'vite-plugin-utils/sort-plugin';\nimport { VIRTUAL_MODULE_PREFIX } from 'vite-plugin-utils/constant';\n\nexport default defineConfig({\n  plugins: [\n    sortPlugin({\n      before: ['vite:vue'],\n      plugin: myPlugin()\n    })\n  ],\n  resolve: {\n    alias: {\n      [`${VIRTUAL_MODULE_PREFIX}my-module`]: '/path/to/my-module'\n    }\n  }\n});\n\nfunction myPlugin() {\n  return {\n    name: 'my-plugin',\n    resolveId(id) {\n      if (id.startsWith(VIRTUAL_MODULE_PREFIX)) return id;\n    }\n  };\n}","lang":"typescript","description":"Shows use of sortPlugin to order a custom plugin before vite:vue and VIRTUAL_MODULE_PREFIX constant for virtual module IDs in a Vite config."},"warnings":[{"fix":"Use import syntax (ESM) or dynamic import() instead of require().","message":"Package is ESM-only. require() will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Use correct subpath import: import { VIRTUAL_MODULE_PREFIX } from 'vite-plugin-utils/constant'.","message":"Subpath exports (e.g., 'constant', 'sort-plugin') must be accessed via full path 'vite-plugin-utils/constant', not from root.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Upgrade to 0.4.0+ and update imports to current subpath exports.","message":"Some APIs in version <0.4.0 used different naming; check changelog for renames.","severity":"deprecated","affected_versions":"<=0.3.x"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change to import statement: import { sortPlugin } from 'vite-plugin-utils/sort-plugin';","cause":"Package is ESM-only. Using CommonJS require() to load it.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /node_modules/vite-plugin-utils/index.js from /project/index.js not supported."},{"fix":"Import from a subpath: import { VIRTUAL_MODULE_PREFIX } from 'vite-plugin-utils/constant';","cause":"Trying to import from package root without specifying subpath export.","error":"Module not found: Can't resolve 'vite-plugin-utils' in '/project'"},{"fix":"Use named imports from subpath exports: import { sortPlugin } from 'vite-plugin-utils/sort-plugin';","cause":"Using default import from package root which exports nothing directly.","error":"Uncaught TypeError: vitePluginUtils is undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}