Copy assets
If you need to copy static files from one location to another, use copy.
Use an array of rule objects to choose which files should be copied.
export default {
copy: [
{
src: "src/assets",
dist: "dist/assets",
},
],
}
If a file matches multiple rules, it will be copied multiple times.
Options
src
The folder or file to copy. The file doesn’t need to be located in your configuration’s src directory, and is relative to the root of your project. This option is required.
dist
The destination of the copied files or folders. When dist is undefined, your configuration’s dist is used. The path is relative to the root of your project, not your configuration’s dist directory.
exclude
A glob pattern matching files you want to exclude from being copied.
include
A glob pattern matching files you want to include in the copy.
flatten
Night Owl will copy the files using the same directory structure as the src directory. If you want all files to be placed at the root of dist, set flatten to true.
transform
Files are copied without any changes. If you want to transform the files as they are copied, use transform.
When set to true, the transform option from your Night Owl configuration is used.
Otherwise, transform should be a function (or array of functions) that takes the content and filename as arguments.
For example, to run SVG files through svgo, you could use the following configuration.
import { optimize } from "svgo"
export default {
copy: [
{
src: "src/assets/icons",
dist: "dist/assets/icons",
include: "**/*.svg",
transform: function (content, filename) {
return optimize(content).data
},
},
],
}
Many transforms are only required when you are building for production. See Running a production build for more details.
buffer
The transform functions receive the file contents as a string. If you want to transform the raw file Buffer instead, set buffer to true. This is useful with images or other binary formats where you don’t want to stringify the file contents.