Introducing a new way to review your PRs.

Read the announcement

frappe / frappe-ui

The all-in-one toolkit for modern frontends. High-quality components, app recipes and AI-ready docs.

View on GitHub

28 documents · Updated Nov 23, 2026

docs / vite-plugins-and-generators

Vite plugins and generators

frappe-ui/vite connects a Frappe application to Vite during development and production. It keeps browser requests on the right Frappe site, reduces the development module graph, turns Frappe schema into TypeScript, carries server data into the client, and provides a shared icon toolchain. See Build and framework integration for the wider build model around this page. See VitePress integration for the related documentation-site entry points.

Vite integration

The Vite integration is a single plugin entry point that assembles several small services. Core development and build services are on by default, while Lucide component tooling and DocType generation are opt-in because they add support that an application may not need.

ServiceMain purposeDefault
Bench file resolutionResolve relative bench site-file imports for linked applicationsOn
Barrel import handlingKeep convenient package imports without loading the full source barrel in developmentOn
Code language handlingLet the code editor build with only the installed CodeMirror language packagesOn
Frappe proxySend backend requests from the Vite server to the local Frappe serverOn
Lucide toolingSupport icon components and icon importsOff
Jinja boot dataPlace selected server values on the browser window in productionOn
Site bannerShow URLs for sites that have the app installedOn when frontendRoute is set
Frappe type generationCreate TypeScript interfaces from selected DocType JSON filesOff

The shared frontendRoute identifies where the front end is served. It links the local site URLs, the production HTML entry, and the compile-time route value used by the application. An options object can change a service; false removes it. Lucide tooling can also be added as a standalone resolver when an application needs ~icons/lucide/* imports but not component auto-imports.

The integration also declares a small set of dependencies for Vite's start-up optimization. This keeps stateful toast and dialog services ready before the first user action instead of discovering them during a page session.

References: vite/index.js• L11-65 vite/index.js• L67-111 vite/index.d.ts• L126-184 vite/lucideIconsPlugin.d.ts• L1-11

Development request routing

The development services make a local Vite page behave like a Frappe page. One service routes site-aware backend traffic. Another narrows the module graph so the browser loads the modules that the page uses instead of walking the whole frappe-ui public entry point.

Frappe proxy

The Frappe proxy is a Vite development-server bridge to the local Frappe web server. It matches Frappe paths such as /api, /app, /assets, /files, and /private, then selects the site from the request host so one development server can serve more than one site.

The proxy gets the backend port from FRAPPE_WEB_SERVER_PORT or the bench common_site_config.json file. If neither is available, it uses the standard Frappe port. The Vite port is then offset from that backend port unless the caller provides one.

The request path through the local system is:

flowchart LR
    Browser[Browser] --> Vite[Vite development server]
    Vite -->|front-end modules| Source[Front-end source]
    Vite -->|Frappe paths| Proxy[Site-aware proxy]
    Proxy --> Backend[Frappe web server]
    Backend --> Site[Site selected from host]

References: vite/frappeProxy.js• L1-51 vite/utils.js• L11-49 vite/index.d.ts• L10-23

Bench file resolution

Bench file resolution makes site-level files available to applications that do not live at their physical path inside the bench. It first keeps normal Vite resolution, then uses the detected bench when a relative import into sites/ cannot resolve in place.

This allows a linked application to use shared bench configuration in the same way as an application stored directly under apps/. The bench comes from the current path or from FRAPPE_BENCH_PATH when the application is linked from outside the bench.

References: vite/benchFiles.js• L4-34 vite/utils.js• L27-49

Barrel import handling

The barrel import service protects development speed without changing the imports that application authors write. A barrel is a package entry that re-exports symbols from many modules. In development, the service maps a known named import to the module that declares it, so a single component does not force Vite to crawl unrelated editors, charts, or network modules.

The service is intended for a working copy of a package and for development only. It leaves namespace imports, side-effect imports, type-only imports, and unknown names safe by keeping them on the public package entry. Production builds can resolve and remove unused barrel exports through the normal bundler path.

References: vite/barrelImports.js• L6-31 vite/barrelImports.js• L228-370 vite/index.d.ts• L35-70

Code language handling

The code language service keeps frappe-ui/code-editor usable when an app installs only the CodeMirror language packages that it needs. It covers both the production build and Vite's development dependency scan, so an unused language does not stop the app before the editor requests it.

The service uses the dependency optimizer that belongs to the installed Vite generation. Older Vite versions use an esbuild bridge, while newer Vite versions use the matching Rollup-style optimizer path. Both paths preserve the same contract: an absent optional language reaches the editor's clear install error instead of failing the whole start-up scan.

When the editor later asks for a language that the app did not install, the service raises a clear missing-package error. An installed package remains the real parser, and imports made directly by the application are not hidden by the service. This keeps optional editor support narrow without masking an app's own dependency errors.

The service is enabled by default through the combined plugin. Turn it off only when the app installs every language package used by the editor or when it needs to manage those imports itself.

References: vite/codeLanguages.js• L1-44 vite/codeLanguages.js• L92-109 vite/codeLanguages.js• L111-169 vite/codeLanguages.js• L171-229 vite/codeLanguages.test.ts• L85-122 vite/codeLanguages.test.ts• L218-289

Frappe schema and runtime data

Frappe supplies two kinds of input to the front end: durable schema from DocTypes and request-time values from the page context. The generators handle these inputs at different times so TypeScript describes records while runtime boot data is available when the production page starts.

DocType interface generation

The Frappe type generator turns selected DocType definitions into TypeScript interfaces. The application gives it an app-to-doctype map and may choose the output file. The generator reads the matching JSON files from the bench and updates the generated file only when a source DocType has changed.

Each generated interface represents the fields that the Frappe schema exposes. Child-table records use the child-document shape, and related table doctypes are included when the selected schema refers to them. This gives application code a typed view of Frappe records without making the generated file the source of truth.

The generator scans each app once for its DocType files and avoids processing a doctype more than once when several selected records refer to it. This keeps related child-table types consistent in the generated output.

The generation flow is:

flowchart LR
    Config[App and DocType map] --> Generator[DocType generator]
    Bench[Bench app JSON] --> Generator
    Generator --> Check[Compare source modification mark]
    Check -->|Changed| Types[Generated TypeScript interfaces]
    Check -->|Unchanged| Keep[Keep existing output]

References: vite/frappeTypes.js• L9-69 vite/generateTypes.js• L10-49 vite/doctypeInterfaceGenerator.js• L22-45 vite/doctypeInterfaceGenerator.js• L87-205

Jinja boot data

Jinja boot data transfers a small set of server values into the production browser page. The Frappe page handler places values in a boot context object; the build output includes a Jinja block that serializes each selected value onto window. Client code can then read session or site data without making a second request just to start the application.

This bridge runs for production HTML, not for the Vite development server. A development page therefore still depends on the normal local Frappe request and session path.

References: vite/jinjaBootData.js• L1-23 vite/index.d.ts• L120-124 vite/index.d.ts• L156-160

Site awareness

The site banner makes the local development entry point visible in a bench with multiple sites. It waits for the Vite server to listen, finds sites where the current Frappe app is installed, and prints each site URL with the configured front-end route.

Bench discovery works for both normal applications and applications linked into apps/ from another folder. FRAPPE_BENCH_PATH provides the bench location for that linked case. Site lookup returns only valid site names and fails closed when the bench command cannot provide a usable list.

The banner is a convenience layer over the same bench and route information used by the proxy and build setup. If the project is not inside a recognizable bench, or the app has no installed sites, it does not invent a URL.

References: vite/siteBanner.js• L1-40 vite/utils.js• L27-49 vite/utils.js• L60-115 vite/utils.js• L117-152

Icon tooling

The icon tooling gives applications one Lucide icon set through CSS classes, explicit Vue components, or template auto-imports. These forms share the same icon names and visual stroke width, but they serve different needs: classes are small and static, while component forms support a real SVG node or a dynamic component reference.

Lucide component tooling

The Lucide component service resolves ~icons/lucide/<name> to a Vue component at build time. It also lets templates use names such as <LucideMenu /> without a manual import when the auto-import layer scans that file. The service accepts both kebab-case names and the naming forms produced from the Lucide catalog. A missing icon produces a visible placeholder and a warning instead of silently leaving an empty component.

The service is off in the combined frappeui plugin by default because class-based icons do not need it. Enable lucideIcons when an application uses component tags or ~icons/lucide/* imports. Applications that import every icon themselves can use the standalone lucideIconsPlugin resolver without the template auto-import layer. The standalone export also exposes the catalog of available icon SVGs for tooling that needs to inspect it.

References: vite/lucideIcons.js• L1-29 vite/lucideIconsPlugin.js• L17-43 vite/lucideIconsPlugin.js• L72-143 vite/index.js• L13-35 vite/index.d.ts• L134-143 vite/lucideIconsPlugin.d.ts• L1-14

Tailwind icon classes

The Tailwind icon tooling exposes each static SVG as a lucide-<name> class. The class uses the element's current text color and scales with the element, so normal size and text-color utilities control the result. Tailwind still emits CSS only for icon class names that it can see in source, which keeps the output small even though the full icon set is available.

The class form replaces an inline SVG when an icon is static. Use the component form when code needs a real SVG node or when the icon choice cannot be known as a literal class during the CSS build.

References: tailwind/lucideIconsPlugin.js• L5-23 tailwind/iconPackPlugin.js• L5-17 tailwind/iconPackPlugin.js• L69-107 docs/…/icons.md• L22-53

Frappe asset handoff

The build configuration connects Vite's output to the Frappe app structure. It places built assets under the app's public area, gives them the URL base that Frappe serves, and copies the built HTML entry to the route-specific www location. This lets the same front end run from Vite in development and from a Frappe page after deployment.

The output and HTML paths can be explicit. When the project follows the usual bench layout, the plugin can infer them from the app directory and frontendRoute. Production builds require a usable HTML destination because Frappe needs that file to render the front end.

References: vite/buildConfig.js• L5-91 vite/buildConfig.js• L94-139 vite/index.d.ts• L87-117

Change checklist

When these files or sections are changed, remember to consider these:

  • A change to frontendRoute affects the site banner URL, the inferred Frappe HTML destination, and the __FRONTEND_ROUTE__ value.
  • A change to proxy path matching or port selection must stay aligned with Frappe's site host routing and the common_site_config.json or environment contract.
  • A change to bench discovery must preserve both normal app paths and linked-app paths. It must also keep bench file resolution and site listing on the same bench.
  • A change to the public package barrel must preserve the import mapper's safe fallback for exports that it cannot attribute to one declaring module.
  • A change to DocType field names or type rules affects generated interfaces and every consumer that treats those interfaces as record shapes.
  • A change to the DocType file scan or de-duplication rules must keep related child-table interfaces in the same generated output.
  • A change to the server's boot keys requires a matching review of client reads from window; production injection does not validate that contract.
  • A change to Lucide names or SVG locations must keep component resolution, the standalone resolver, and Tailwind class generation aligned. Also keep the combined plugin's opt-in behavior clear.
  • A change to the editor's optional language list must keep the code-language stubs aligned with loadLanguage and both Vite dependency-optimizer paths; otherwise a missing package can fail dependency pre-bundling before the editor runs.

Important failure modes

TriggerConsequenceGuard
The proxy uses a wrong backend port or an incomplete source pattern.API, asset, or page requests fail in development or reach the wrong service.Check FRAPPE_WEB_SERVER_PORT, bench site configuration, and the request paths that the app needs.
The project runs outside a detectable Frappe bench and has no valid FRAPPE_BENCH_PATH.Site links, shared site-file imports, and automatic app or output discovery are unavailable.Set FRAPPE_BENCH_PATH or paths explicitly when the project does not use the standard bench layout.
A relative import into sites/ is used by a linked app but bench file resolution is disabled or cannot find the bench.Shared bench configuration fails to resolve during the Vite build.Run with a detectable bench or provide FRAPPE_BENCH_PATH.
A DocType name in frappeTypes.input has no matching JSON file.Its interface is not generated, so typed record access is missing or incomplete.Keep the app-to-doctype map aligned with the bench app schema.
A production page does not provide the expected boot context.The injected globals are absent or contain no usable value when the client starts.Populate context.boot in the Frappe handler and use only known keys in client code.
An icon class is assembled dynamically.Tailwind emits no rule for the requested icon, so the icon does not render.Use complete literal class names or import a component for data-driven choices.
The combined plugin stays at its default while the app uses Lucide component tags or ~icons/lucide/* imports.Explicit imports fail to resolve, while unimported component tags warn and render nothing.Enable lucideIcons or add the standalone lucideIconsPlugin when the app needs component tooling.
A virtual Lucide name is not in the static icon set.The page shows a placeholder icon and Vite reports a warning.Replace the name with a supported icon or an explicit SVG asset.
The editor reaches an optional language package that the app did not install and code-language handling is disabled.The Vite build or dependency scan stops before the app starts.Keep codeLanguages enabled or install every language package used by the editor.

Key files

FileWhy to read it
vite/index.jsShows how the Vite entry point composes the services, applies defaults, shares frontendRoute, and prepares dependency optimization.
vite/index.d.tsDefines the public configuration contract for consuming Vite projects.
vite/README.mdGives the user-facing setup model and the main choices for each plugin.
vite/frappeProxy.jsExplains local request routing and Frappe port selection.
vite/benchFiles.jsExplains how linked applications resolve shared bench site files.
vite/utils.jsExplains bench discovery, linked-app detection, and installed-site lookup.
vite/barrelImports.jsExplains why development imports are narrowed and when they remain unchanged.
vite/codeLanguages.js and vite/codeLanguages.test.tsExplain how optional CodeMirror language packages stay optional across builds and development dependency scans.
vite/frappeTypes.jsConnects Vite startup with the separate type-generation process.
vite/doctypeInterfaceGenerator.jsDefines the relationship between Frappe DocType schema and generated interfaces.
vite/jinjaBootData.jsShows the production bridge from Jinja page data to browser globals.
vite/siteBanner.jsShows how bench sites become local development URLs.
vite/lucideIcons.js, vite/lucideIconsPlugin.js, and vite/lucideIconsPlugin.d.tsExplain the combined icon service, standalone resolver, and public icon declarations.
tailwind/iconPackPlugin.js and tailwind/lucideIconsPlugin.jsExplain the class-based SVG icon path.
vite/buildConfig.jsShows how Vite output becomes a Frappe app asset and HTML entry.