gulp文件包含不处理文件

时间:2019-02-11 14:33:41

标签: gulp

让我的吞吃任务“ fileinclude”无法正常工作。只是尝试使用gulp 4.0设置我的gulp文件,而过去工作正常的任务不再起作用,如果我运行“ gulp fileinclude”,我得到的只是“ Starting'fileinclude'...”,它不会输出任何文件或给出我有任何错误,谁能看到我可能在做错的事情,我在下面添加了gulpfile.js。

var gulp = require("gulp"),
  sass = require("gulp-sass"),
  cssnano = require("cssnano"),
  postcss = require("gulp-postcss"),
  autoprefixer = require("autoprefixer"),
  sourcemaps = require("gulp-sourcemaps"),
  fileinclude = require('gulp-file-include'),
  browserSync = require("browser-sync").create(),
  reload = browserSync.reload();

var paths = {
  styles: {
    src: "app/scss/**/*.scss",
    dest: "dev/css"
  },
  html: {
    src: "app/views/*.html",
    dest: "dev"
  },
  js: {
    src: "app/js/**/*.js",
    dest: "dev/js"
  }
};

function style() {
  return (
    gulp
      .src(paths.styles.src)
      .pipe(sourcemaps.init())
      .pipe(sass())
      .on("error", sass.logError)
      .pipe(postcss([autoprefixer(), cssnano()]))
      .pipe(sourcemaps.write())
      .pipe(gulp.dest(paths.styles.dest))
  );
}

function fileinclude() {
  return (
    gulp
    .src(["./app/views/**/*.html"])
    .pipe(fileinclude({
      basepath: 'app/views/'
    }))
    .pipe(gulp.dest("dev"))
    .pipe(browserSync.stream())
  )
}

function watch() {
  browserSync.init({
    server: "dev"
  });
  style();
  gulp.watch(paths.styles.src, style);
  gulp.watch(paths.html.src, fileinclude);
}

exports.style = style;
exports.fileinclude = fileinclude;
exports.watch = watch

编辑:如果我从gulp 3.9返回到旧任务,我就可以正常使用

gulp.task("fileinclude", function() {
  gulp.src(["./src/views/**/*.html"])
    .pipe(fileinclude({
      basepath: 'src/views/'
    }))
    .pipe(gulp.dest("./dev"))
    .pipe(browserSync.stream());
});

gulp.task('include-watch', ['fileinclude'], browserSync.reload);

0 个答案:

没有答案