packages/browser-sync/lib/plugins.js
function requirePlugin(item) {
    /**
     * if the "module" property already exists and
     * is not a string, then we bail and don't bother looking
     * for the file
     */
    if (item.get("module") && typeof item.get("module") !== "string") {
        return item;
    }

    try {
        /**
         * Try a raw node require() call - this will be how
         * regular "npm installed" plugins wil work
         */
        var maybe = require.resolve(item.get("name"));
        return item.set("module", require(maybe));
    } catch (e) {
        /**
         * If require threw an MODULE_NOT_FOUND error, try again
         * by resolving from cwd. This is needed since cli
         * users will not add ./ to the front of a path (which
         * node requires to resolve from cwd)
         */
        if (e.code === "MODULE_NOT_FOUND") {
            var maybe = path.resolve(process.cwd(), item.get("name"));
            if (fs.existsSync(maybe)) {
                return item.set("module", require(maybe));
            } else {
                /**
                 * Finally return a plugin that contains the error
                 * this will be picked up later and discarded
                 */
                return item.update("errors", function(errors) {
                    return errors.concat(e);
                });
            }
        }
        throw e;
    }
}
function requirePlugin(item) {
    /**
     * if the "module" property already exists and
     * is not a string, then we bail and don't bother looking
     * for the file
     */
    if (item.get("module") && typeof item.get("module") !== "string") {
        return item;
    }

    try {
        /**
         * Try a raw node require() call - this will be how
         * regular "npm installed" plugins wil work
         */
        var maybe = require.resolve(item.get("name"));
        return item.set("module", require(maybe));
    } catch (e) {
        /**
         * If require threw an MODULE_NOT_FOUND error, try again
         * by resolving from cwd. This is needed since cli
         * users will not add ./ to the front of a path (which
         * node requires to resolve from cwd)
         */
        if (e.code === "MODULE_NOT_FOUND") {
            var maybe = path.resolve(process.cwd(), item.get("name"));
            if (fs.existsSync(maybe)) {
                return item.set("module", require(maybe));
            } else {
                /**
                 * Finally return a plugin that contains the error
                 * this will be picked up later and discarded
                 */
                return item.update("errors", function(errors) {
                    return errors.concat(e);
                });
            }
        }
        throw e;
    }
}
function requirePlugin ( item ) { /**
     * if the "module" property already exists and
     * is not a string, then we bail and don't bother looking
     * for the file
     */ if ( item . get ( "module" ) && typeof item . get ( "module" ) !== "string" ) { return item ; } try { /**
         * Try a raw node require() call - this will be how
         * regular "npm installed" plugins wil work
         */ var maybe = require . resolve ( item . get ( "name" ) ) ; return item . set ( "module" , require ( maybe ) ) ; } catch ( e ) { /**
         * If require threw an MODULE_NOT_FOUND error, try again
         * by resolving from cwd. This is needed since cli
         * users will not add ./ to the front of a path (which
         * node requires to resolve from cwd)
         */ if ( e . code === "MODULE_NOT_FOUND" ) { var maybe = path . resolve ( process . cwd ( ) , item . get ( "name" ) ) ; if ( fs . existsSync ( maybe ) ) { return item . set ( "module" , require ( maybe ) ) ; } else { /**
                 * Finally return a plugin that contains the error
                 * this will be picked up later and discarded
                 */ return item . update ( "errors" , function ( errors ) { return errors . concat ( e ) ; } ) ; } } throw e ; } }
Load a plugin from disk
@param item
@returns {*}
Load a plugin from disk