From 275274e611ca7272bb34870bfe2c665b37db25d4 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Mon, 21 Apr 2014 20:04:55 -0700 Subject: [PATCH] use .match to inject the script, instead of cheerio --- lib/util/liveReloadStream.js | 20 ++++++++++---------- package.json | 3 +-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/util/liveReloadStream.js b/lib/util/liveReloadStream.js index 7ce9afd..e670729 100644 --- a/lib/util/liveReloadStream.js +++ b/lib/util/liveReloadStream.js @@ -1,14 +1,14 @@ -var through2 = require('through2'); -var cheerio = require('cheerio'); +var map = require('through2-map'); +var match = /<\/body>/i; +var script = function(port) { + return ""; +}; module.exports = function (lrPort) { - return through2.obj(function(file, enc, next) { - var script = ""; - var html = file.toString('utf8'); - var $ = cheerio.load(html); - $('body').append(script); - - this.push($.html()); - next(); + return map({wantStrings: true}, function(chunk) { + if (chunk.indexOf(match)) { + chunk = chunk.replace(match, script(lrPort)+''); + } + return chunk; }); }; \ No newline at end of file diff --git a/package.json b/package.json index a701cd7..96dcc10 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,9 @@ "gulp": "~3.2.0", "gulp-util": "~2.2.0", "portfinder": "~0.2.1", - "cheerio": "~0.13.1", "minimist": "0.0.8", "mime": "~1.2.11", - "through2": "~0.4.1" + "through2-map": "~1.2.1" }, "devDependencies": { "mocha": "*",