-
Notifications
You must be signed in to change notification settings - Fork 12
Description
In my Metalsmith build scripts I've added support for conditional plugins. I achieve this by wrapping the existing plugin in a new conditional plugin. It looks like this in the Metalsmith build pipeline:
// Conditionally watch and serve with BrowserSync.
.use(conditionalWatchMode(browserSync(browserSyncOptions)))And the conditional wrapper looks something like this simplified version:
function conditionalWatchMode (plugin) {
return function (files, metalsmith, done) {
if (isWatchEnabled) {
plugin(files, metalsmith, done);
} else {
done();
}
};
}However, this wrapped plugin model causes problems with this metalsmith-browser-sync plugin because the plugin depends upon the availability of a plugin name property to prevent multiple instances of browserSync from starting. When this plugin is wrapped, the wrapping plugin doesn't echo the _pluginName property and therefore the bs plugin is never removed from the chain. The end result is that everything seems to work fine, but browserSync doesn't pick up the updated content when the sources have changed (it notices that the files have changed and refreshes the browser, but still serves the old/original content).
I've thrown together an example build script and package.json in this Gist.