Night Owl logoNight Owl

Configuration

Configuration for Night Owl is optional. For simple sites, you may not need to change any of the default settings.

Night Owl looks for a nightowl.js configuration file at the root of your project.

The file is a module that declares an object as the default export. For example, a basic configuration file might change the default src directory.

export default {
  src: "./site",
}

Options

You can find all of Night Owl’s configuration defaults here.

src

The input directory where the source files are located. By default, Night Owl uses the "src" directory.

dist

The directory where generated files will be created. By default, Night Owl uses the "dist" directory.

data

The path to the global data module. See Global Data for more details.

port

The port to use when serving files. See the Serve command for more details.

host

The host to use when serving files. See the Serve command for more details.

templates

Configure which files are considered templates. You can set include and exclude, both of which are an array of glob patterns.

{
  "templates": {
    "include": [],
    "exclude": ["**/_*", "**/.*", "**/_*/**"]
  }
}

The default include option is empty, so all files in the source directory are included.

On the other hand, exclude ignores any files that start with an underscore or a period. It also excludes files located in a subdirectory that starts with an underscore.

copy

Copy files from one directory to another. See Copy assets for more details.

watch

An array of glob patterns adding other paths to watch. See Watching other files for more details.

watchAndRestart

Like watch, but changes to these files will restart Night Owl. By default, Night Owl will restart when nightowl.js or package.json change. You can add other files to trigger a restart. The contents of files are not checked, so every time these files are touched Night Owl restarts, even if their contents are unchanged.

transform

The transform option allows you to run additional modifications after your template is rendered. This option takes a function or an array of functions. Each function is invoked with the rendered content string and filename of the template as arguments.

For example, you could use transform to minify your HTML files.

import { minify } from "html-minifier"

export default {
  transform: [
    function (content, filename) {
      if (filename.endsWith(".html")) {
        return minify(content)
      } else {
        return content
      }
    },
  ],
}

Remember to return the content even if your function doesn’t transform the file.

Many transforms are only required when you are building for production. See Running a production build for more details.

compilers

Set compiler options and add support for new template types. See Compilers for more details.

trailingSlash

If enabled, Night Owl will append a trailing slash when generating page URLs. The default value for trailingSlash is true.

excludeHidden

When excludeHidden is enabled, a template with hide set to true will be excluded from the build. The default value is true.

stripSortPrefix

Night Owl sorts collections based on template file names. To create user‑friendly URLs, any numbers followed by a hyphen or underscore are removed from the start of files and directories. Disable this feature by setting stripSortPrefix to false.

importThreshold

JavaScript files are cache‑busted when they are imported, but Node doesn’t garbage collect unused imports. The importThreshold prevents Night Owl using too much memory by restarting after a threshold is reached. The default value is 9999.

maxLayoutDepth

Layouts can be nested. To prevent an endless chain of nesting circular imports, layouts will only be nested up to the maxLayoutDepth. The default value is 10.

tempDirectory

Night Owl occassionally writes temporary files to disk. The default tempDirectory location is ".nightowl".

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": "Configuration",
  "description": "Control the way Night Owl generates your site",
  "url": "/docs/configuration/",
  "meta": {
    "url": "/docs/configuration/",
    "src": "src/docs/03-configuration/01-index.md",
    "dist": "dist/docs/configuration/index.html",
    "collections": {
      "all": [...],
      "intro": [...],
      "commands": [...],
      "configuration": [...],
      "advanced": [...],
      "templates": [...]
    }
  },
  "content": "<p>Configuration for Night Owl is optional. For simple sites, you may not need t..."
}