vitefu
raw JSON → 1.1.3 verified Sat Apr 25 auth: no javascript
vitefu provides utilities for building frameworks with Vite, including `crawlFrameworkPkgs` to scan dependencies and `isDepExternaled` to check externalization status. Current stable version is 1.1.3, released in March 2025. It supports Vite 3–8 as peer dependencies and is updated regularly (multiple releases per year). Key differentiators: wraps Vite's internal logic for framework authors, handles workspace crawling, and is used by SvelteKit and Astro. It ships TypeScript types and ESM/CJS exports.
Common errors
error TypeError: Cannot destructure property 'optimizedDeps' of (intermediate value) as it is undefined. ↓
cause crawlFrameworkPkgs called before Vite config is resolved (e.g., in config instead of configResolved hook).
fix
Move the call inside the 'configResolved' hook as shown in the quickstart.
error Error: Failed to crawl framework packages: ENOENT: no such file or directory, open '.../package.json'. ↓
cause crawlFrameworkPkgs expects a package.json at the root; before v1.0.6, missing package.json caused an error.
fix
Upgrade to v1.0.6+ which gracefully handles missing package.json, or ensure root has a package.json.
error Module not found: Can't resolve 'vitefu' ↓
cause vitefu is not installed or not in node_modules.
fix
Run npm install vitefu (or yarn/pnpm add vitefu). It requires Vite as a peer dependency.
Warnings
gotcha crawlFrameworkPkgs result arrays are sorted deterministically only since v1.1.3; earlier versions may produce non-deterministic order. ↓
fix Upgrade to v1.1.3 or later, or sort arrays manually.
gotcha workspaceRoot option in crawlFrameworkPkgs introduced in v1.1.0; it enables crawling devDependencies of local workspace private packages, but may require proper workspace configuration. ↓
fix Ensure workspaceRoot points to the root of your monorepo and that private packages have package.json with devDependencies.
gotcha isDepExternaled may not handle ssr.external: true (boolean) correctly before v1.0.6; it expects an array of strings. ↓
fix Upgrade to v1.0.6 or later, or convert boolean ssr.external to array manually.
breaking v1.0.0 removed top-level await to allow future compatibility with require() of ESM code. If you depend on top-level await, this breaks. ↓
fix Wrap initialization in async function if you need top-level await.
gotcha findDepPkgJsonPath implementation changed in v0.2.5 to align with Vite; older versions may return inconsistent paths compared to Vite's own resolution. ↓
fix Upgrade to v0.2.5 or later.
Install
npm install vitefu yarn add vitefu pnpm add vitefu Imports
- crawlFrameworkPkgs wrong
import crawlFrameworkPkgs from 'vitefu'correctimport { crawlFrameworkPkgs } from 'vitefu' - isDepExternaled wrong
const isDepExternaled = require('vitefu').isDepExternaledcorrectimport { isDepExternaled } from 'vitefu' - findDepPkgJsonPath wrong
import { findAllPkgJsonPaths } from 'vitefu'correctimport { findDepPkgJsonPath } from 'vitefu'
Quickstart
import { crawlFrameworkPkgs } from 'vitefu';
import { defineConfig } from 'vite';
export default defineConfig({
optimizeDeps: {
include: [],
},
ssr: {
external: [],
},
async configResolved(config) {
const { optimizedDeps, ssr } = await crawlFrameworkPkgs({
root: __dirname,
viteConfig: config,
frameworkPkg: 'my-framework',
});
config.optimizeDeps.include = optimizedDeps;
config.ssr.external = ssr.external;
},
});