npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

metalsmith-static-files

v2.0.0

Published

A Metalsmith plugin to copy a directory to the build directory

Readme

metalsmith-static-files

A Metalsmith plugin to copy a directory to the build directory

metalsmith:plugin npm: version license: MIT coverage ESM/CommonJS Known Vulnerabilities

Features

  • This plugin supports both ESM and CommonJS environments with no configuration needed:
    • ESM: import staticFiles from 'metalsmith-static-files'
    • CommonJS: const staticFiles = require('metalsmith-static-files')

Installation

npm install metalsmith-static-files

Usage

Pass metalsmith-static-files to metalsmith.use. The source directory path is resolved to metalsmith.directory(). The destination path is resolved to metalsmith.destination().

Typically, you want to use this plugin somewhere at the start of the chain, before any asset plugins are run, like @metalsmith/sass.

metalsmith.use(
  staticFiles({
    source: 'src/assets/',
    destination: 'assets/'
  })
)

Options

The plugin accepts the following options:

| Option | Type | Default | Description | | -------------------- | --------- | ------------ | ------------------------------------------------------ | | source | string | src/assets | Source directory path relative to Metalsmith root | | destination | string | assets | Destination directory path relative to build directory | | overwrite | boolean | true | Whether to overwrite existing files | | preserveTimestamps | boolean | false | Whether to preserve timestamps when copying files | | ignore | array | - | Array of glob patterns to exclude files (optional) |

Examples

Basic Usage

import Metalsmith from 'metalsmith'
import staticFiles from 'metalsmith-static-files'

Metalsmith(__dirname)
  .source('./src')
  .destination('./build')
  .use(staticFiles())
  .build((err) => {
    if (err) throw err
    console.log('Build complete!')
  })

With Options

import Metalsmith from 'metalsmith'
import staticFiles from 'metalsmith-static-files'

Metalsmith(__dirname)
  .source('./src')
  .destination('./build')
  .use(
    staticFiles({
      source: 'static',
      destination: 'public',
      overwrite: false,
      preserveTimestamps: true,
      ignore: ['**/*.tmp', '**/*.log'] // Exclude temporary files
    })
  )
  .build((err) => {
    if (err) throw err
  })

Advanced Usage

Using Ignore Patterns

metalsmith.use(
  staticFiles({
    source: 'static',
    destination: 'public',
    overwrite: false, // Don't overwrite existing files
    preserveTimestamps: true, // Keep original timestamps
    ignore: ['**/*.tmp', '**/*.bak', '**/cache/**'] // Exclude temporary files and cache
  })
)

Common Use Cases

// Exclude specific files
metalsmith.use(
  staticFiles({
    source: 'lib/assets/',
    destination: 'assets/',
    ignore: ['main.css', 'main.js'] // Exclude processed files
  })
)

// Exclude entire directories (all patterns work the same)
metalsmith.use(
  staticFiles({
    source: 'lib/assets/',
    destination: 'assets/',
    ignore: ['styles/', 'temp/', 'cache/'] // Exclude entire directories
  })
)

// Mixed patterns
metalsmith.use(
  staticFiles({
    source: 'lib/assets/',
    destination: 'assets/',
    ignore: [
      '*.tmp', // Exclude temp files
      '*.log', // Exclude log files
      'styles/', // Exclude styles directory
      'node_modules/', // Exclude node_modules directory
      '**/.DS_Store' // Exclude .DS_Store files everywhere
    ]
  })
)

Directory Exclusion Patterns

Key Feature: All directory patterns exclude the entire directory structure - no empty directories are created.

All of these patterns have identical behavior and exclude the complete directory:

  • 'styles/' - Directory with trailing slash
  • 'styles/*' - All files in directory
  • 'styles/**' - Directory and all subdirectories

Important: The plugin excludes directories at the directory level, not just their contents. This means when you use any of these patterns, the entire styles/ directory and everything inside it will be completely excluded from the copy operation. No empty styles/ directory will be created in the destination.

Example:

Source directory:
assets/
├── images/
│   └── logo.png
├── styles/
│   ├── main.css
│   └── components/
│       └── button.css
└── scripts/
    └── app.js

With ignore: ['styles/']

Result directory:
assets/
├── images/
│   └── logo.png
└── scripts/
    └── app.js

Notice: No empty styles/ directory is created - it's completely excluded.

Debug

To enable debug logs, set the DEBUG environment variable to metalsmith-static-files:

DEBUG=metalsmith-static-files

CLI usage

To use this plugin with the Metalsmith CLI, add metalsmith-static-files to the plugins key in your metalsmith.json file:

{
  "plugins": [
    {
      "metalsmith-static-files": {}
    }
  ]
}

Author

[email protected]

License

MIT