javascript Gulp:简单的SCSS处理

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Gulp:简单的SCSS处理相关的知识,希望对你有一定的参考价值。

const gulp = require("gulp");
const browserSync = require("browser-sync").create();
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");

var options = {
  autoprefixer: {
    browsers: [
      "last 3 versions",
      "ie >= 8",
      "ios >= 7",
      "android >= 4.4",
      "bb >= 10"
    ],
    cascade: false
  },
  sass: {
    outFile: "./",
    outputStyle: "compressed",
    sourceMap: true,
    sourceMapEmbed: true
  }
};

gulp.task("serve", function() {
  browserSync.init({
    baseDir: "./",
    proxy: "localhost/wordpress/example/"
  });

  gulp.watch("scss/**/*.scss", ["style"]).on("change", browserSync.reload);
  gulp.watch("**/*.php").on("change", browserSync.reload);
});

gulp.task("style", function() {
  return gulp
    .src("./scss/style.scss")
    .pipe(sass(options.sass).on("error", sass.logError))
    .pipe(autoprefixer(options.autoprefixer))
    .pipe(gulp.dest("./"))
    .pipe(browserSync.stream());
});

gulp.task("default", ["style", "serve"]);
const gulp = require("gulp");
const browserSync = require("browser-sync").create();
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");

var options = {
  autoprefixer: {
    browsers: [
      "last 2 versions",
      "ios >= 7",
      "android >= 4.4",
      "bb >= 10"
    ],
    cascade: false
  },
  sass: {
    outFile: "./",
    outputStyle: "expanded",
    sourceMap: false,
    sourceMapEmbed: false
  }
};

gulp.task("serve", function() {
  browserSync.init({
    server: "./"
  });

  gulp.watch("scss/**/*.scss", ["style"]).on("change", browserSync.reload);
  gulp.watch("**/*.html").on("change", browserSync.reload);
  gulp.watch("**/*.php").on("change", browserSync.reload);
});

gulp.task("style", function() {
  return gulp
    .src("./scss/style.scss")
    .pipe(sass(options.sass).on("error", sass.logError))
    .pipe(autoprefixer(options.autoprefixer))
    .pipe(gulp.dest("./"))
    .pipe(browserSync.stream());
});

gulp.task("default", ["style", "serve"]);
const gulp = require("gulp");
const browserSync = require("browser-sync").create();
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");

var options = {
  autoprefixer: {
    browsers: [
      "last 3 versions",
      "ie >= 8",
      "ios >= 7",
      "android >= 4.4",
      "bb >= 10"
    ],
    cascade: false
  },
  sass: {
    outFile: "./",
    outputStyle: "compressed",
    sourceMap: true,
    sourceMapEmbed: true
  }
};

gulp.task("serve", function() {
  browserSync.init({
    server: "./"
  });

  gulp.watch("scss/**/*.scss", ["style"]).on("change", browserSync.reload);
  gulp.watch("**/*.html").on("change", browserSync.reload);
});

gulp.task("style", function() {
  return gulp
    .src("./scss/style.scss")
    .pipe(sass(options.sass).on("error", sass.logError))
    .pipe(autoprefixer(options.autoprefixer))
    .pipe(gulp.dest("./"))
    .pipe(browserSync.stream());
});

gulp.task("default", ["style", "serve"]);

以上是关于javascript Gulp:简单的SCSS处理的主要内容,如果未能解决你的问题,请参考以下文章

Gulp-sass 无法编译 scss 文件

Sass和gulp的简单了解

gulp的简单应用

Glob观看多个文件,处理一个

Gulp执行预处理

Gulp 3 到 Gulp 4:如何观看 scss 并将其缩小/编译成 css?