copyFileToDest
Copy one or more files of any type into destination directories, with support for custom output roots, file renaming, and absolute target paths.
Overview
copyFileToDest is a utility for copy one or more files of any type into destination directories.
This utility is file-type agnostic and can be used to copy any kind of asset, including CSS, JavaScript, JSON, images, fonts, or other static files.
- The function supports:
- Copying a single file using a single configuration object.
- Copying multiple files using an array or a Set of configuration objects.
- When using a Set, it is recommended to use
createCopyFileToDestParameterSet()to ensure proper TypeScript inference and autocomplete support.
Why use this?
- Copy static assets directly into your build output directories.
- Organize files using custom target folders or output roots.
- Rename files during copy for cleaner distribution structure.
- Supports batch copying with arrays or Set configurations.
- Useful for CSS, JavaScript, JSON, images, fonts, and other static assets.
Importing
Syntax
Parameters
Prop
Type
param
The parameter options for copying a file.
A single CopyFileToDestParam object, an array, or a Set of CopyFileToDestParam.
-
When a collection is provided:
- Each item is validated independently.
- Files are copied sequentially.
- Logging reflects the cumulative copy progress.
-
Example:
TypeScript/JavaScript
source
-
Description:
Path to the source file to be copied, can be either an absolute path or a path relative to the project root. -
Required:
-
Type:
string -
Default:
- -
Example:
TypeScript/JavaScript
target
-
target:
Target directory where the file will be copied. -
Required:
-
Type:
string -
Default:
- -
Example:
TypeScript/JavaScript
Notes
- When
absoluteTargetisfalse(default), this path is resolved relative tooutputRoot. - When
absoluteTargetistrue, this path is treated as an absolute path relative to the project root.
fileName
-
fileName:
Optional custom file name for the copied file. -
Required:
-
Type:
string -
Default:
undefined -
Example:
TypeScript/JavaScript
Note
If omitted, the original file name from source will be preserved.
outputRoot
-
outputRoot:
Output root directory used when resolving thetargetpath. -
Required:
-
Type:
string -
Default:
"dist" -
Example:
TypeScript/JavaScript
Note
When absoluteTarget is false, the final copy destination will be <project-root>/<outputRoot>/<target>.
absoluteTarget
-
absoluteTarget:
Use this when you want to copy directly to an absolute path inside the project, bypassing theoutputRootprefix. -
Required:
-
Type:
boolean -
Default:
false -
Example:
TypeScript/JavaScript
Note
When true, disables outputRoot prefixing and treats target as an absolute path relative to the project root.
ignoreMissingSourceError
-
ignoreMissingSourceError:
Whentrue, suppresses errors when the source file does not exist. -
Required:
-
Type:
boolean -
Default:
false -
Example:
TypeScript/JavaScript
Notes
- Instead of throwing or logging an error, the operation will be skipped.
- Useful in development or watch mode where build outputs may not be immediately available.
options
Optional configuration object that defines how the utility function should behave in various scenarios, allowing customization and greater control at runtime.
logLevel
-
Description:
Controls how detailed the logger output should be during execution.Supported values
silent➔ no output.error➔ errors only.info➔ standard logs (default).debug➔ verbose logs.
Notes
- Invalid values are automatically reset to default.
- All levels include error output except
silent.
-
Required:
-
Type:
"error"|"silent"|"info"|"debug" -
Default:
"info" -
Example:
TypeScript/JavaScript
Helper
createCopyFileToDestParameterSet
Creates a Set of parameters for copy-file-to-dest.
Utility helper to construct a Set of CopyFileToDestParam with proper type inference and editor autocomplete support.
This is primarily useful when passing parameters as a Set, since directly using new Set([...]) may result in poor TypeScript inference and missing autocomplete for object literals.
-
Behavior:
- Accepts a single parameter or an array of parameters.
- Automatically normalizes the input into a
Set.
-
Example:
TypeScript/JavaScript
Returns
Returns a Promise<void>.
The function performs asynchronous file processing and does not return any value.
Version information
- Since:
v0.0.7. - Category:
copy. - Stability: ✅
Stable(Production-ready).
