Metalsmith plugin to watch for changes and trigger partial and full rebuilds
npm install metalsmith-watch> Metalsmith plugin to watch for changes and trigger partial and full rebuilds.
``console`
$ npm install metalsmith-watch
`js
var metalsmith = require('metalsmith');
var watch = require('metalsmith-watch');
metalsmith(__dirname)
.use(
watch({
paths: {
"${source}/*/": true,
"templates//": "/.md",
},
livereload: true,
})
)
.build();
`
Map of paths to trigger rebuild. Both keys and value accept a glob pattern.
`js`
{
"file(s) to watch": "file(s) to rebuild"
}
Value accept a boolean. When a boolean is used, only watched files changed will be rebuilded.
`js`
{
"${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().metalsmith.source()
- _values of the map are relative to _ (because it's the only place where to build files)
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
``
Make sure to update the port number in the script above accordingly to the port specified.
Function used to display the logs.
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.