diff --git a/src/inject/expected/issue177.html b/src/inject/expected/issue177.html
new file mode 100644
index 0000000..42a3f75
--- /dev/null
+++ b/src/inject/expected/issue177.html
@@ -0,0 +1,17 @@
+
+
+
+ gulp-inject
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/inject/index.js b/src/inject/index.js
index 8713278..9bcaeb2 100644
--- a/src/inject/index.js
+++ b/src/inject/index.js
@@ -130,6 +130,7 @@ function getNewContent(target, collection, opt) {
endTag: endTag,
tagsToInject: tagsToInject,
removeTags: opt.removeTags,
+ empty: opt.empty,
willInject: function (filesToInject) {
injectedFilesCount += filesToInject.length;
},
@@ -151,6 +152,7 @@ function getNewContent(target, collection, opt) {
endTag: endTag,
tagsToInject: [],
removeTags: opt.removeTags,
+ empty: opt.empty,
shouldAbort: function (match) {
return matches.indexOf(match[0]) !== -1;
}
@@ -207,8 +209,10 @@ function inject(content, opt) {
var newContents = content.slice(0, startMatch.index);
if (opt.removeTags) {
- // Take care of content length change:
- startTag.lastIndex -= startMatch[0].length;
+ if (opt.empty) {
+ // Take care of content length change:
+ startTag.lastIndex -= startMatch[0].length;
+ }
} else {
// +
toInject.unshift(startMatch[0]);
diff --git a/src/inject/inject_test.js b/src/inject/inject_test.js
index 29086f3..8588706 100644
--- a/src/inject/inject_test.js
+++ b/src/inject/inject_test.js
@@ -471,6 +471,23 @@ describe('gulp-inject', function () {
streamShouldContain(stream, ['removeTags.html'], done);
});
+ it('should be able to remove tags without removing whitespace (issue #177)', function (done) {
+ var target = src(['template.html'], {read: true});
+ var sources = src([
+ 'lib.js',
+ 'component.html',
+ 'styles.css',
+ 'morestyles.css',
+ 'andevenmore.css',
+ 'image.png',
+ 'lib.jsx'
+ ]);
+
+ var stream = target.pipe(inject(sources, {removeTags: true}));
+
+ streamShouldContain(stream, ['issue177.html'], done);
+ });
+
it('should not produce log output if quiet option is set', function (done) {
var logOutput = [];
gutil.log = function () {