metalsmith-include-files
TypeScript icon, indicating that this package has built-in type declarations

3.0.2 • Public • Published

metalsmith-include-files

npm: version npm: downloads

Snyk: vulnerabilities codecov: coverage license

A Metalsmith plugin to include external files in your build.

A common use case is wanting to include JavaScript, CSS, or font files from an installed NPM package such as bootstrap.

Installation

npm install --save metalsmith-include-files

JavaScript Usage

const Metalsmith = require('metalsmith');
const include    = require('metalsmith-include-files');

Metalsmith(__dirname)
    .use(include({
        directories: { /* ... */ }
        // other options here
    }))
    .build((err) => {
        if (err) {
            throw err;
        }
    });

Options

directories (required)

Type: object

A dictionary where the keys are Metalsmith build output directories, and the values are an array of micromatch patterns for files on your filesystem.

Example structure:

{
  "directories": {
    "[output directory 1]": [
      "[micromatch pattern 1]",
      "[micromatch pattern 2]"
    ],
    "[output directory 2]": [
      "[micromatch pattern 3]",
      "[micromatch pattern 4]"
    ]
  }
}

overwrite (optional)

Type: boolean Default: false

Whether existing files in the Metalsmith build output can be overwritten or not. An exception will be raised if the option is false and there is a duplicate filename.

Example

To include a number of static assets from jquery, bootstrap, and @fortawesome/fontawesome-free in your output files:

const include = require('metalsmith-include-files');

Metalsmith(__dirname)
    .use(include({
        directories: {
            'static/css': [
                './node_modules/bootstrap/dist/css/bootstrap.min.css',
                './node_modules/@fortawesome/fontawesome-free/css/all.min.css'
            ],
            'static/js': [
                './node_modules/jquery/dist/jquery.slim.js',
                './node_modules/bootstrap/dist/js/bootstrap.min.js'
            ],
            'static/webfonts': [
                './node_modules/@fortawesome/fontawesome-free/webfonts/*'
            ]
        }
    }))

Changelog

Changelog

Package Sidebar

Install

npm i metalsmith-include-files

Weekly Downloads

28

Version

3.0.2

License

GPL-3.0-or-later

Unpacked Size

44.4 kB

Total Files

6

Last publish

Collaborators

  • emmercm