Change some html code into antoher with GULP
<p>Thank you for checking my question. This may sound trivial but I need help here.</p>

<p>I want to learn how to <strong>change HTML code</strong> with <strong>GULP</strong>. Or just <strong>change some strings</strong> with <strong>GULP</strong>. For example today I need to change this:</p>

<pre><code>&lt;img class="social" src="../symbols/facebook.svg"&gt;
</code></pre>

<p>to this:</p>

<pre><code>&lt;svg class="social"&gt;
    &lt;use xlink:href="../symbols/sprite.svg?v201608061556#facebook"&gt;&lt;/use&gt;
&lt;/svg&gt;
</code></pre>

<p>As you can see I am building icon system via <strong>symbols</strong> and I want to keep my original HTML clean as it can be. So I can work without any watchers and such. Later I just run GULP once and it does the job: create sprite and change HTML to use this sprite.</p>

<p>I tried <a href="https://www.npmjs.com/package/gulp-replace" rel="nofollow noreferrer">gulp-replace</a> and it can change one string to another with <strong>regex</strong>, but it looks too complicated for me with regex. I am not even sure that it is possible to do with regex. And I also want to add timestamp as <strong>?v201608061556</strong>. So I want to run some JavaScript that I can write in gulp file.</p>

<p>Next one I tried is <a href="https://www.npmjs.com/package/gulp-dom" rel="nofollow noreferrer">gulp-dom</a> and it looks like the thing I need. But I can't make it work due to some errors:</p>

<pre><code>if (node.nodeType === NODE_TYPE.DOCUMENT_NODE) {
        ^
TypeError: Cannot read property 'nodeType' of undefined
</code></pre>

<p>Error log in terminal:
<a href="https://i.stack.imgur.com/uL7x5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uL7x5.png" alt="gulp-dom error output"></a></p>

<p>So the questions is:</p>

<ol>
<li>Is it possible to make with <strong>regex</strong> and <strong>gulp-replace</strong> package?</li>
<li>Does anyone know <strong>gulp-dom</strong>
package. Can I make it work somehow? Is it possible to complete my
task with it? </li>
<li>Is there another way to write JavaScript in Gulp task
so I can take a string, process it according to my needs with all JavaScript functionality and save? </li>
<li>Can I work with HTML from Gulp the same way
I work when I code websites? Work with DOM, use
<strong>querySelector</strong> and <strong>classList</strong> for example? Maybe jQuery?</li>
</ol>

<p>Thanks.</p>