繁体   English   中英

Gulp:使用多个 PHP 文件

[英]Gulp: useref multiple PHP files

我最近在我的一个网站上开发了第二个页面,我将其放在我的项目文件夹中,以便可以像“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')那样做,但这也不起作用。 有任何想法吗?

我认为你在这里有些倒退。 您必须将您的索引文件输入到 userref 中。 这意味着您的源不是应用程序中的每个 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'))

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM