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

How to watch for changes the assets #161

Closed manuel-di-iorio closed 8 years ago

manuel-di-iorio commented 8 years ago

Assume you have a gulp task like that:

gulp.task('html', function() {
    return gulp.src( ['raw_assets/views/**/*.+(html|php)'] )
        .pipe( watch(['raw_assets/views/**/*.+(html|php)']) )
        .pipe( useref({
            searchPath: "raw_assets",
            base: basePath
        }) )
        .pipe( gulpIf("*.js", uglify() ))
        .pipe( gulp.dest("app/views/www") )
        .pipe( browserSync.reload( {stream: true} ))
        .pipe( notify('HTML task complete!') );
});

With this approach, to compile i.e. a JS script, I have everytime to edit and save the html file, that contains the useref buildblock. What is the best practice to watch for changes the assets so that I can save only the modified asset, using in some way the useref task (concatenating, compress, etc..) ?

jonkemp commented 8 years ago

Why are you watching the files to run uglify everytime the file changes? Doesn't that defeat the purpose of useref?

In any case, check out the plugins for incremental builds.

https://github.com/gulpjs/gulp#incremental-builds

manuel-di-iorio commented 8 years ago

Why are you watching the files to run uglify everytime the file changes? Doesn't that defeat the purpose of useref? That's the point. I need useref to concatenate the assets (specifyng them in html) and uglify to compress it, but I want also to detect the changes on the assets themselves and not only on the html file.

I'll take a look on the incremental builds plugins, thanks :+1:

It would be awesome if useref could do this thing automatically. It should save the references of the assets and exec the task of the html when a change is detected.

jonkemp commented 8 years ago

Great! Can we close this?

manuel-di-iorio commented 8 years ago

If you want.. so, it's not possible to detect changes to the assets automatically with useref?

jonkemp commented 8 years ago

No, and no plans to add that functionality. Gulp.js guidelines for developing plugins explicitly state that 1. plugins should not do something that can easily be done with other existing plugins or modules and 2. plugins should be as simple as possible, typically only doing one function.

https://github.com/gulpjs/gulp/blob/master/docs/writing-a-plugin/guidelines.md

This plugin is already complex and difficult to maintain. I am adhering to these guidelines as much as possible.