2016-04-04 47 views
2

我最近在我的一個網站上開發了第二個頁面,我把它放在我的項目文件夾中,因此可以像「www.mysite.com/projects」一樣訪問我的目錄:gulp:useref多個PHP文件

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

我咕嘟咕嘟文件:

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')) 

}); 

但是,當我執行命令來運行useref,它不useref項目中的PHP文件或到我的DIST文件夾移動文件夾。我試過像return gulp.src('app/**/*.php')這樣做,但那也行不通。有任何想法嗎?

回答

2

我想你在這裏倒退了一些東西。你必須輸入你的索引文件的useref。也就是說你的來源是不是在你的應用程序的每個PHP文件,但

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

然後,你要告訴useref到哪裏尋找index.html中引用與所有文件:

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

而且在這種情況下,您只需要一個dest。這使你的任務:

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')) 

});