如何只编译已经用gulp更改过的sass文件?

时间:2015-01-12 15:52:51

标签: ruby sass gulp gulp-watch gulp-sass

我有吞咽的问题。我正在使用gulp-watch和gulp-ruby-sass来编译scss文件,当有些东西发生变化时,问题是,我只改变一个文件并编译文件夹上的所有文件,而我只想编译更改的文件。我尝试使用插件gulp-changed但得到了相同的结果。

2 个答案:

答案 0 :(得分:0)

假设您将一个scss文件编译为另一个css文件(例如header.scss到header.css),您可以使用gulp-newer仅编译已更改的文件:

https://www.npmjs.com/package/gulp-newer

答案 1 :(得分:-1)

你可以使用gulp-changed

这是我的例子http://lizhug.com/tech/gulp-changed-gulp-sass-only-compile-files-that-changed/



uglifycss = require "gulp-uglifycss"
watch = require "gulp-watch"
changed = require "gulp-changed"

##编译scss文件
gulp.task 'sass', ->
  gulp.src "src/scss/**/*.scss"
  .pipe(changed("assets/css", {extension: ".min.css"}))   //this is right              {".css"} is wrong because i use rename ".min"
  .pipe(sass())
  .on "error", logError
  .pipe autoprefixer
  browsers: ['last 3 versions'],
     cascade: true, #是否美化属性值 默认:true 像这样:
      remove:true #是否去掉不必要的前缀 默认:true
  .pipe uglifycss()
  .pipe rename suffix: '.min'
  .pipe gulp.dest 'assets/css'
  .pipe livereload()

#编译coffee文件
gulp.task "coffee", ->
  gulp.src "src/js/**/*.coffee", read:false
    .pipe(changed("assets/js", {extension: ".min.js"}))
    .pipe browserify
      debug: true
      transform: ['coffeeify']
      extensions: ['.coffee']
    .on "error", logError
    .pipe uglify()
    .pipe rename suffix: ".min"
    .pipe extReplace '.js'
    .pipe gulp.dest "assets/js"
    .pipe livereload()

#编译coffee文件
gulp.task "coffee", ->
  gulp.src "src/js/**/*.coffee", read:false
    .pipe(changed("assets/js", {extension: ".js"}))
    .pipe browserify
      debug: true
      transform: ['coffeeify']
      extensions: ['.coffee']
    .on "error", logError
    .pipe uglify()
    .pipe extReplace '.js'
    .pipe gulp.dest "assets/js"
    .pipe livereload()