Snorlax
Snorlax

Reputation: 4765

Gulp: useref multiple PHP files

I recently developed a second page on one of my websites which I put in my projects folder so it can be accessed like "www.mysite.com/projects" My directory looks like this:

|js
|css
|projects - has index.php 
|img
index.php
mailer.php

My Gulp file:

I used Gulp useref like this:
gulp.task('useref', function(){
  return gulp.src('app/*.php')
    .pipe(useref())
        // Minifies only if it's a JavaScript file
    .pipe(gulpIf('*.js', uglify()))
    .pipe(gulp.dest('dist'))
    // Minifies only if it's a CSS file
    .pipe(gulpIf('*.css', cssnano()))
    .pipe(gulp.dest('dist'))

});

But when I execute the command to run useref, it doesn't useref the php file in projects or move the folder over to my dist folder. I tried doing it like return gulp.src('app/**/*.php') but that doesn't work either. Any ideas?

Upvotes: 2

Views: 752

Answers (1)

Wilmer SH
Wilmer SH

Reputation: 1417

I think you have something backwards here. You have to pipe into useref your index file. Meaning that your source is not every php file in your app, but

gulp.src('your_Path/index.html')

Then, you have to tell useref where to look for all the files referenced in index.html with:

.pipe(useref({
    searchPath: 'app/' // I'm guessing this is the path
}))

Also, you only need one dest in this case. Which makes your task:

gulp.task('useref', function(){

  return gulp.src('your_Path/index.html') // Check this path
     .pipe(useref({
         searchPath: 'app/' // Check this path
     }))
    // Minifies only if it's a JavaScript file
    .pipe(gulpIf('*.js', uglify()))
    // Minifies only if it's a CSS file
    .pipe(gulpIf('*.css', cssnano()))
    .pipe(gulp.dest('dist'))

});

Upvotes: 2

Related Questions