Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapping plugin causes browserSync issues #4

Open
claycarpenter opened this issue May 23, 2015 · 0 comments
Open

Wrapping plugin causes browserSync issues #4

claycarpenter opened this issue May 23, 2015 · 0 comments

Comments

@claycarpenter
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant