BoxLang ๐ A New JVM Dynamic Language Learn More...
๐ Seamless Vite integration for ColdBox applications with automatic development/production mode switching.
This ColdBox module provides a powerful vite()
helper
function for loading assets generated by Vite and the coldbox-vite-plugin
. It intelligently handles both development (hot reload) and
production (manifest-based) modes automatically.
<script>
and <link>
tag creationInstall via CommandBox:
box install vite-helpers
In your ColdBox views, use the vite()
helper to load
your assets:
<!--- Load a single JavaScript entry point --->
#vite('resources/assets/js/app.js')#
<!--- Load a CSS file --->
#vite('resources/assets/css/app.css')#
<!--- Load multiple assets --->
#vite(['resources/assets/js/app.js', 'resources/assets/css/app.css'])#
<!--- Get asset paths without rendering tags --->
<cfset assetPaths = vite().getAssetPaths(['app.js', 'app.css']) />
<!--- Custom configuration --->
#vite()
.setBuildDirectory('/custom/build')
.setManifestFileName('custom-manifest.json')
.render('app.js')#
The module operates in two distinct modes:
/includes/hot
file exists<script type="module" src="http://127.0.0.1:5173/@vite/client"></script>
<script type="module" src="http://127.0.0.1:5173/resources/assets/js/app.js"></script>
/includes/hot
file
doesn't exist<link rel="modulepreload" href="/includes/build/assets/app-5b5efed9.js" />
<script type="module" src="/includes/build/assets/app-5b5efed9.js"></script>
Configure the module in your ModuleConfig.cfc
or
override in your main config/ColdBox.cfc
:
// In your ModuleConfig.cfc or ColdBox.cfc
moduleSettings = {
"vite-helpers" = {
"hotFilePath" : "/includes/hot", // Hot reload detection file
"buildDirectory" : "/includes/build", // Production build output
"manifestFileName" : ".vite/manifest.json" // Vite manifest file
}
};
Setting | Default | Description |
---|---|---|
hotFilePath
| /includes/hot
| ๐ฅ Path to hot file that signals development mode |
buildDirectory
| /includes/build
| ๐ Directory where Vite outputs production assets |
manifestFileName
| .vite/manifest.json
| ๐ Vite's asset manifest file name |
This module is designed to work seamlessly with the coldbox-vite-plugin
:
Install the Vite plugin in your frontend project:
npm install coldbox-vite-plugin --save-dev
Configure your vite.config.js
:
import { defineConfig } from 'vite'
import coldbox from 'coldbox-vite-plugin'
export default defineConfig({
plugins: [
coldbox({
input: ['resources/assets/js/app.js', 'resources/assets/css/app.css']
})
]
})
npm run dev
http://127.0.0.1:5173
npm run build
Run the test suite:
# Navigate to the test runner
box server start
# Then visit: http://localhost:{port}/tests/runner.cfm
# Or use TestBox CLI
box testbox run
getAssetPaths(
entrypoints )
entrypoints
(string|array)
- Asset entry points to resolve<cfset paths = vite().getAssetPaths(['app.js', 'app.css']) />
render( entrypoints )
entrypoints
(string|array)
- Asset entry points to render#vite().render('app.js')#
We welcome contributions! Please see our Contributing Guidelines for details.
box install
box testbox run
box run-script format
See CHANGELOG.md for release history and updates.
Made with โค๏ธ by the ColdBox Team
$
box install vite-helpers