我最近在我的一个网站上开发了第二个页面,我把它放在我的项目文件夹中,这样就可以像"www.mysite.com/projects"一样访问它。我的目录如下:
|js
|css
|projects - has index.php
|img
index.php
mailer.php
我的Gulp文件:
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
的命令时,它不会在项目中使用php文件,也不会将文件夹移到我的dist文件夹中。我试着像return gulp.src('app/**/*.php')
那样做,但也不起作用。有什么想法吗?
我想你在这里有些倒退。您必须通过管道将索引文件导入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'))
});