使用Gulp BrowserSync呈现PHP文件

时间:2016-04-08 20:27:02

标签: gulp

我一直在使用Gulp并尝试构建一些进程,其中一个是BrowserSync。事情是我希望它在PHP文件上重载,但它似乎只想呈现html文件。我怎么能绕过这个?我的gulp文件在这里:

// gulpfile.js
var gulp = require('gulp');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var flatten = require('gulp-flatten');
var browserSync = require('browser-sync').create();

// Live reload (HTML Only)
gulp.task('browser-sync', function() {
  browserSync.init({
    server: {
      baseDir: "app/build/"
    }
  });
  gulp.watch("app/scss/*.scss", ['minify-css']);
});

// Sass Compile
gulp.task('sass', function(){
  return gulp.src('app/src/scss/**/*.scss')
    .pipe(sass()) // Converts Sass to CSS with gulp-sass
    .pipe(gulp.dest('app/build/css/'))
    .pipe(browserSync.stream())
});

// Minify CSS after Scss Compile
gulp.task('minify-css', ['sass'], function() {
  return gulp.src('app/build/css/*.css')
    .pipe(gulp.dest('app/build/css/'))
});

// Compress JS
gulp.task('minify-js', ['flatten'], function() {
  return gulp.src('app/src/js/*.js')
    .pipe(uglify())
    .pipe(gulp.dest('app/build/js/'))
});

gulp.task('flatten', function() {
  gulp.src('bower_components/**/')
    .pipe(flatten({ includeParents: [1, 1]}))
    .pipe(gulp.dest('app/build/js/'))
});

gulp.task('watch', ['browser-sync'], function (){
  gulp.watch('app/src/scss/*.scss', ['minify-css']);
  gulp.watch('app/src/js/*.js', ['minify-js', browserSync.reload])
})

gulp.task('default', ['watch']);

2 个答案:

答案 0 :(得分:1)

尝试添加以下行:

(define (operList op i)
  (lambda (lis)
    (if (null? lis)
        '()
        (cons (op i (car lis))
              ((operList op i) (cdr lis))))))

答案 1 :(得分:1)

  1. 安装AppServ

  2. 将您的项目放到C:\ AppServ \ www目录

  3. 更改

    gulp.task('browser-sync', function() {
     browserSync.init({
      server: {
        baseDir: "app/build/"
      }
    });
    

    gulp.task('browser-sync', function() {
      browserSync({
        proxy: "http://localhost/ PUT HERE NAME OF YOUR PROJECT 
           FOLDER/app/build/%NAME OF YOUR PHP FILE%.php"
    
    });