Download the PHP package chialab/vite-cakephp without Composer
On this page you can find all versions of the php package chialab/vite-cakephp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chialab/vite-cakephp
More information about chialab/vite-cakephp
Files in chialab/vite-cakephp
Package vite-cakephp
Short Description Vite plugin for CakePHP
License MIT
Homepage https://github.com/chialab/vite-cakephp
Informations about the package vite-cakephp
Vite plugin for CakePHP
A Vite plugin and CakePHP helper that connect a Vite build to a CakePHP application. The plugin produces a single JSON manifest that the helper reads to emit the correct <script> and <link> tags in both development and production.
Requirements
| Dependency | Version |
|---|---|
| PHP | ≥ 8.3 |
| CakePHP | ^4.5 |
| Vite | ^6.0 |
Installation
The Vite plugin ships inside the Composer package — no separate npm install is needed.
Setup
1. Bootstrap the plugin
2. Load the helper
Pass configuration options as the second argument if the defaults do not match your project layout (see PHP helper options):
3. Configure Vite
Usage
Call js() and css() independently in your layout or view templates. The logical entry name is {group.name}/{entry}:
Both methods return an empty string when the manifest file is absent (no dev server running, no build present), so they are always safe to call.
CSS-only and JS+CSS entries
Configuration reference
Vite plugin options
vitePhp(inputs: BuildGroup[]) accepts an array of build groups.
BuildGroup
Each group maps to one Rollup build with its own output directory, public URL, and entry files.
| Field | Type | Default | Description |
|---|---|---|---|
name |
string |
— | Namespace prefix for logical entry names, e.g. "app". |
inputs |
Record<string, EntryInput> |
— | Local entry name → source file mapping (see below). |
outDir |
string |
— | Output directory for this group's assets, relative to the project root. |
publicPath |
string |
— | Public URL base where outDir is served (baked into the manifest paths). |
format |
"es" \| "iife" |
"es" |
Build format. "iife" produces a self-contained bundle suitable for file:// pages. |
external |
string[] |
[] |
External module IDs (meaningful for "iife" groups). |
EntryInput
Each entry in inputs can be written in two ways:
Multiple groups example
Logical names for the above: app/home, app/product, app/styles, embed/widget.
PHP helper options
| Option | Type | Default | Description |
|---|---|---|---|
buildPath |
string\|null |
WWW_ROOT . 'dist' |
Absolute filesystem path to the build directory (where Vite writes outDir). |
basePath |
string |
'/dist/' |
Public URL prefix prepended to relative paths from the manifest. A leading / is resolved relative to the application base by HtmlHelper. |
fileName |
string |
'.vite/php.json' |
Path to the manifest file, relative to buildPath. |
buildPath must match the outDir you configure in Vite. For example, if Vite writes to webroot/dist, set buildPath to WWW_ROOT . 'dist' (the default) or an equivalent absolute path.
Runtime behaviour
The plugin writes a single file — {outDir}/.vite/php.json — whose mode field drives the helper's behaviour.
Development
Start the Vite dev server normally:
On server start the plugin writes:
js() emits a <script type="module"> pointing at the dev server, preceded by @vite/client (deduplicated across all calls). css() emits a <script type="module"> for CSS entries — Vite serves CSS files as ESM modules with HMR. When the dev server exits the file is removed.
Production
Build with:
The plugin writes:
js() emits <link rel="modulepreload"> for each import chunk (ESM) followed by <script type="module">, or a classic <script> for IIFE entries. css() emits <link rel="stylesheet"> for each CSS file.
No manifest
When the file is absent (not built, dev server not running) both js() and css() return an empty string. In debug mode an unknown mode value throws a RuntimeException.