gulp-html-replace icon indicating copy to clipboard operation
gulp-html-replace copied to clipboard

Treats JS script like a url to JS script

Open Maxim-Mazurok opened this issue 1 year ago • 1 comments

I have the following template:

<!-- Hotjar Tracking Code -->
<script>
    (function (h, o, t, j, a, r) {
        h.hj =
            h.hj ||
            function () {
                (h.hj.q = h.hj.q || []).push(arguments);
            };
        h._hjSettings = { hjid: '%HJID%', hjsv: '%HJSV%' };
        a = o.getElementsByTagName('head')[0];
        r = o.createElement('script');
        r.async = 1;
        r.src = t + h._hjSettings.hjid + j + h._hjSettings.hjsv;
        a.appendChild(r);
    })(window, document, 'https://static.hotjar.com/c/hotjar-', '.js?sv=');
</script>

And I was using this plugin like so:

function createCopyHTMLTask(env) {
    return gulp
        .src(html, { base: './' })
        .pipe(
            gulpHtmlReplace({
                hotJar: fs.readFileSync(hotJarTemplatePath, 'utf-8')
            }),
        )
        .pipe(gulp.dest(distPath));
}

And because of this logic: https://github.com/VFK/gulp-html-replace/blob/HEAD/lib/block.js#L65-L69

My script was added like this:

<script src="<!-- Hotjar Tracking Code --> <script> (function (h, o, t, j, a, r) { h.hj =...

Which is obviously not right

Maxim-Mazurok avatar Sep 18 '23 04:09 Maxim-Mazurok

I have resolved my issue by using this instead:

gulpHtmlReplace({
    hotJar: {
        src: null,
        tpl: hotJarContents,
    },
});

Maxim-Mazurok avatar Sep 18 '23 04:09 Maxim-Mazurok