Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

metalsmith-watch

FWeinb1.9kMIT1.0.3

Metalsmith plugin to watch for changes and trigger partial and full rebuilds

metalsmith, metalsmith-plugin

readme

metalsmith-watch Build Status NPM version

Metalsmith plugin to watch for changes and trigger partial and full rebuilds.

Installation

$ npm install metalsmith-watch

Usage

var metalsmith = require('metalsmith');
var watch = require('metalsmith-watch');

metalsmith(__dirname)
  .use(
    watch({
      paths: {
        "${source}/**/*": true,
        "templates/**/*": "**/*.md",
      },
      livereload: true,
    })
  )
  .build();

Options

paths (default: {"${source}/**/*": true})

Map of paths to trigger rebuild. Both keys and value accept a glob pattern.

{
  "file(s) to watch": "file(s) to rebuild"
}

Value accept a boolean. When a boolean is used, only watched files changed will be rebuilded.

{
  "${source}/**/*": true, // every changed files will trigger a rebuild of themselves
  "templates/**/*": "**/*", // every templates changed will trigger a rebuild of all files
}

Please note that:

  • ${source} is replaced by metalsmith.source().
  • values of the map are relative to metalsmith.source() (because it's the only place where to build files)

livereload (default: false)

Allows you to enable a livereload server. Using a boolean will enable a livereload server on port the default port is 35729. Accept a port number to start on the port you need.

To get live reload working properly, you should add the following <script> in your templates files to enable livereloading of each pages:

<script src="http://localhost:35729/livereload.js"></script>

Make sure to update the port number in the script above accordingly to the port specified.

log (default: function(...args) { console.log(prefix, ...args)})

Function used to display the logs.

invalidateCache (default: true)

Allows you to enable cache invalidation for js files. Convenient if you use some js files for templates (eg: React templates) to get updated components. If disabled you won't get update for changed js files as node/iojs use a cache.

Changelog

License

changelog

1.0.3 - 2016-06-07

  • Fixed: absolute source path doesn't make the pattern matcher fail anymore (#30 - @zakhenry)

1.0.2 - 2016-05-16

  • Fixed: remove deprecated warnings related to dependencies (#29)

1.0.1 - 2015-05-09

  • Fixed: the plugin works correctly without any options provided (#21)

1.0.0 - 2015-05-08

  • Fixed: metalsmith-collections are now correctly adjusted to avoid duplicates entries after rebuilds)
  • Removed: pattern option has been remove. Please use the new paths option
  • Added: paths option allows you to specify a map to trigger rebuilds (closes #4 and #13)
  • Added: log option to be able to control watcher logs
  • Added: when a JavaScript file is changed, the corresponding cache in node/iojs cache is refreshed. This is particularly handy when working with plain JavaScript template (eg: react template made with metalsmith-react)

0.2.1

  • Fixed: Use metalsmith .build() method instead of .run().

0.2.0

  • Changed: Update to work with metalsmith 1.0

0.1.1

  • Added: ability to use an array to define multiple glob parameters.

0.1.0

  • Changed: To conform to other plugins watch must be used like watch() now.
  • Fixed: keep track of renamed files correctly (#5)

0.0.4

  • Added: support for livereload (#3).

0.0.3

0.0.2

  • Fixed: repositiory url in package.json

0.0.1

✨ Initial release