Copy Assets Plugin
A staticbolt plugin that copies asset files from your source directory to the build output at the end of a production build. Files that other plugins already handled, such as converted images or optimized SVGs, are skipped so the originals do not overwrite them.
Installation
The plugin ships as part of @staticbolt/core. You do not need to install anything else.
Usage
In your .staticbolt.ts configuration file:
import { defineConfig } from "@staticbolt/core";import { copyAssetsPlugin } from "@staticbolt/core/plugins";
export default defineConfig({ plugins: [copyAssetsPlugin()],});By default the plugin takes everything under sources/assets/ and keeps each file's path relative to the project root. It also takes everything in the public directory (publicDir in the config, public by default), which lands at the root of the output directory with the directory name itself dropped. For example, public/favicon.ico is written to dist/favicon.ico. Dotfiles are taken as well. The plugin only runs during production builds and has no effect in development.
Each file is registered as a binary asset once every transform has run, and the write files plugin copies it. That is what lets the cache bust plugin version assets like any other output file. A path another plugin already emits is skipped, and so are assets other plugins already handled (converted images, optimized SVGs). The originals cannot replace them.
Plugin Options
include
- Type:
string[] - Default:
["sources/assets/**/*"]
Glob patterns for the files to copy to the output directory.
copyAssetsPlugin({ include: ["src/assets/**/*", "public/**/*"],});exclude
- Type:
string[] - Default:
[]
Glob patterns for files to skip when copying. They apply to both the include patterns and the public directory.
copyAssetsPlugin({ exclude: ["sources/assets/raw/**"],});