jonkemp / gulp-useref

Parse build blocks in HTML files to replace references to non-optimized scripts or stylesheets.
MIT License
705 stars 93 forks source link

Removing a block completely #232

Closed hetsch closed 7 years ago

hetsch commented 7 years ago

Wether I've missed some important parts of the documentation but if have a code like

<html>
  <head>
    <meta charset="UTF-8">
    <title>Timetracker</title>
    <!-- build:remove -->
    <script>require('electron-connect').client.create()</script>
    <!-- endbuild -->
 </head>
 ...

I would expect that the <script>*</script> tag is entirely removed from the resulting output html. What happens here is that only the comment tags are removed, leaving the script tag behind in the markup.

<html>
  <head>
    <meta charset="UTF-8">
    <title>FooBar</title>
    <script>require('electron-connect').client.create()</script>
 </head>
 ...

I've debugged it with the following code:

    .pipe(useref({ 
        noconcat: true, 
        noAssets: true
    }))
    .pipe(through.obj(function(file, enc, callback) {
        if (file.path.endsWith('frontend/foobar.html')) {
            console.log(file.contents.toString())
        }

        this.push(file);
        callback();
    }))

Is this behavior intended and do I have to write my own block handler for this? Thank's for your help!

jonkemp commented 7 years ago

Yes, the documentation is correct. It should work like it says there. Looking at the tests for this plugin, there are not any for this feature. However, the useref module does have tests and they all pass when you run them.

https://github.com/jonkemp/useref/blob/master/test/test.js

So I'm at a loss to explain why it doesn't work. Maybe we could write a test for the gulp plugin and see if that works.

hetsch commented 7 years ago

@jonkemp Sorry for the late response. All is good now. It seems that I had some quirks with my modules and installed them fresh. Problem solved and I close the ticket. Thank you for your help and time!