Static Assets Plugin
Documentation for the Coralite static asset plugin used to copy files during the build process.
The staticAssetPlugin is a built-in Coralite utility that orchestrates copying raw files directly into the final build directory. It supports both local path resolution and NPM package traversal to pull binary assets (like .wasm files), images, or scripts out of node_modules.
Configuration
The plugin is automatically initialized if you provide an assets array to the Coralite configuration. Each object in the array must contain a dest (destination) property.
Local File Resolution
If the asset object contains a src property, the plugin copies the file or directory directly from your local file system.
// coralite.config.js
export default defineConfig({
assets: [
{ src: './src/public/favicon.ico', dest: 'favicon.ico' },
{ src: './src/docs/pdf', dest: 'assets/pdf' } // Copies whole directory
]
});
NPM Package Resolution
If src is missing, you must provide pkg and path options. The plugin uses Node's resolution logic to find the package root and then appends the provided path.
// coralite.config.js
export default defineConfig({
assets: [
{
pkg: '@matrix-org/matrix-sdk-crypto-wasm',
path: 'pkg/matrix_sdk_crypto_wasm_bg.wasm',
dest: 'assets/js/matrix_sdk_crypto_wasm_bg.wasm'
}
]
});
How it Works
- Hook: The plugin triggers during the
onBeforeBuildlifecycle hook. - Reliability: It ensures all required binary or static dependencies are physically present in the output directory before Coralite attempts to render pages or start the development server.
- Automation: It recursively creates destination directories as needed.