3
votes

Im having a problem with gulp. Im using gulp-watch and gulp-ruby-sass to compile the scss files when something changes, the problem is, im changing just one file and compiles all the files on the folder, and a I just want to compile the file that changed. I tried to use the plugin gulp-changed but got the same result.

2

2 Answers

0
votes

Assuming that you compile one scss file to another css file (for example header.scss to header.css), you can use gulp-newer to compile only the changed file:

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

-1
votes

you can use gulp-changed

this is my example 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()