Night Owl logoNight Owl

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.

Page data

This page was rendered with the following data.

{
  "layout": "_/layouts/docs",
  "menu": {...},
  "filters": {...},
  "helpers": {...},
  "version": "0.5.4",
  "github": "https://github.com/stephenhutchings/night-owl/",
  "npm": "https://www.npmjs.com/package/night-owl",
  "hash": "lmu1z5z4",
  "thumbnail": "https://night-owl.s-ings.com/assets/thumb.png",
  "isDev": false,
  "tags": [ "configuration" ],
  "title": "Copy assets",
  "description": "Copy static files to your `dist` directory",
  "url": "/docs/configuration/copy/",
  "meta": {
    "url": "/docs/configuration/copy/",
    "src": "src/docs/03-configuration/02-copy.md",
    "dist": "dist/docs/configuration/copy/index.html",
    "collections": {
      "all": [...],
      "intro": [...],
      "commands": [...],
      "configuration": [...],
      "advanced": [...],
      "templates": [...]
    }
  },
  "content": "<p>If you need to copy static files from one location to another, use <code>copy..."
}