Copy static files

Configure what files and directories are copied as is.

Static files are files that don't have to be processed, like images, PDFs, videos or audio. So it's better (and faster) to copy these files directly to the dest directory with the copy() method:

// Copy the "img" directory to _site/img

// Copy the file to _site/favicon.ico

The path is relative to the source directory of your site (configured in src), and the files and directories are copied as is, maintaining the same directory structure. Use the second argument to change the output directory:

// Copy the "img" directory to _site/images
site.copy("img", "images");

// Copy the "static-files/favicons/favicon.ico" to _site/favicon.ico
site.copy("static-files/favicons/favicon.ico", "favicon.ico");

// Copy the content of "assets" directory to the root of your site
site.copy("assets", ".");

Ignored files

Note that the ignore settings explained in Ignore files are applied when copying static files, including files starting with _ and .. for example:

// Ignore a subfolder

// Copy the /files/ folder.
// Note that the /files/pictures/ folder is ignored,
// in addition to all files starting with . and _

If you need to copy a file starting with . or _, you have to configure it explicitly:

// Copy a underscored file

Copy by file extension

An additional way to select files is by extension. Use an array with the extensions of the files that you want to copy:

// Copy all image files
site.copy([".jpg", ".gif", ".png"]);

This will copy all files with the extensions .jpg, .gif and .png, keeping the original file structure. For example, the file /img/pictures/image.jpg will be copied into _site/img/pictures/image.jpg location.

Customize the destination

For more fine-tuning of the file destination, you can provide a function in the second argument that accepts the original file path and must return the destination path:

// Copy all files in the static directory but ensure they are lower case
site.copy("static", (file) => file.toLowerCase());

// Copy all images in the /img/ directory
site.copy([".jpg", ".gif", ".png"], (file) => "/img" + file);

The copied files are not processed, even if they have known extensions like .md, .njk, etc.