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 can you return original path if path is not defined in build comments? #170

Open rooksstrife opened 8 years ago

rooksstrife commented 8 years ago

I am using gulp useref to replace my files in my index.html after I minify them. I can get useref to work when I pass a path, but I would like to have it keep the file's original path when I don't define a path. I know I could go through and add the build path comment to each file or that I could just run a task to minify all other files. That just seems crazy and pointless if useref can output the original path then this task to would do it all.

Also posted the question on Stackoverflow: http://stackoverflow.com/questions/34794378/gulp-useref-how-can-you-return-original-path

Example - to note stripped code for example aka rel="".

HTML file:

<!-- build:css I want this to return original path into my new "dist" folder. Like **/* -->
    <link href="fonts/map/map.css">
    <link href="layout/item/item.css">
<!-- endbuild -->

this works bc path is defined and the files exist in the same folder.

<!-- build:css styles/combined.css -->
    <link href="styles/style.css">
    <link href="styles/color.css">
<!-- endbuild -->

Gulp Task:

gulp.task('css', function () {
        return gulp.src('index.html')
            .pipe(useref())
            .pipe(minifyCss())
            .pipe(gulp.dest('dist'));
    });

Resulting HTML - the index.html file is outputed to the "dist" folder and the .css files are minified. This all works, but noticed the href = "replace" bc nothing was defiened in the comments for path, also a file named undefined is outputed in the dist folder:

<link href="replace">
<link href="css/combined.css">

and what I want is...

<link href="fonts/map/map.css">
<link href="layout/item/item.css">
<link href="css/combined.css">