{"id":22772,"library":"vite-plugin-package-config","title":"Vite Plugin Package Config","description":"A Vite plugin (v0.1.1, latest) that allows extending Vite configuration via a `vite` field in package.json. Developed by Anthony Fu, it provides a declarative, JSON-based alternative to vite.config.ts for static config like resolve aliases and build output, making it easier to share and manipulate config across tools. It requires Vite ^2.0.0, ships TypeScript types, and has a minimal API — just one function call.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/antfu/vite-plugin-package-config","tags":["javascript","vite-plugin","typescript"],"install":[{"cmd":"npm install vite-plugin-package-config","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-package-config","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-package-config","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin only works with Vite's plugin system.","package":"vite","optional":false}],"imports":[{"note":"Default ESM import is the intended usage. CJS require() may work but is not recommended and not tested.","wrong":"const PkgConfig = require('vite-plugin-package-config')","symbol":"PkgConfig","correct":"import PkgConfig from 'vite-plugin-package-config'"},{"note":"The package exports a single function as default. Named import will result in undefined.","wrong":"import { PkgConfig } from 'vite-plugin-package-config'","symbol":"default","correct":"import PkgConfig from 'vite-plugin-package-config'"},{"note":"The package does not export a named type. Use Vite's Plugin type directly.","wrong":"import { VitePluginPackageConfig } from 'vite-plugin-package-config'","symbol":"type definitions","correct":"import type { Plugin } from 'vite'; import PkgConfig from 'vite-plugin-package-config'"}],"quickstart":{"code":"// vite.config.ts\nimport PkgConfig from 'vite-plugin-package-config';\nimport { defineConfig } from 'vite';\n\nexport default defineConfig({\n  plugins: [\n    PkgConfig()\n  ]\n});\n\n// package.json\n{\n  \"name\": \"my-app\",\n  \"version\": \"1.0.0\",\n  \"vite\": {\n    \"resolve\": {\n      \"alias\": {\n        \"@\": \"/src\"\n      }\n    },\n    \"build\": {\n      \"outDir\": \"dist\"\n    }\n  }\n}","lang":"typescript","description":"Shows how to install and use the plugin to extend Vite config from package.json's 'vite' field."},"warnings":[{"fix":"Use vite.config.ts for dynamic configurations.","message":"Only static config that can be JSON-serialized is supported. Functions, objects with circular references, or dynamic values cannot be placed in package.json.","severity":"gotcha","affected_versions":"*"},{"fix":"Explicitly set precedence by ordering plugins or using the 'enforce' property.","message":"The plugin merges config from package.json with vite.config.ts; duplicate config fields may cause unexpected behavior depending on merge order.","severity":"gotcha","affected_versions":"*"},{"fix":"Use Vite's official config fields like 'outDir' instead of 'output'.","message":"The 'output' alias field (e.g., 'build.output') is deprecated in Vite; use 'outDir' instead.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Ensure process.cwd() matches the directory containing package.json, or set root in Vite config.","message":"The plugin reads package.json from the project root; if the root is not correctly configured, it may fail silently.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run 'npm install -D vite-plugin-package-config'.","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'vite-plugin-package-config'"},{"fix":"Use 'import PkgConfig from \"vite-plugin-package-config\"'.","cause":"Named import used instead of default import.","error":"TypeError: PkgConfig is not a function"},{"fix":"Ignore the warning; the plugin parses it correctly.","cause":"The custom 'vite' field is not part of Vite's official schema but is read by the plugin.","error":"Invalid config: field 'vite' in package.json is not recognized"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}