2016-04-04 18 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')) 

});