zaebalo
zaebalo

Reputation: 157

Gulp doesnt watch for imported sass modules

I'm trying to set up gulp and watch for files change and then reload browserSync. Modifying main.sass file is working fine, but when imported in main.sass files are modified, gulp doesnt see it. Same happens to pug, modifying includes is hidden for gulp-watch.

What I've tried:

  1. includePaths in some ways

  2. tried to write in gulp.src() path like 'desktop/css/**/*.sass', but it caused that imported modules were compiled in a separate file, which is wrong behavior (not as I expected, sadly).

My imported files are in desktop/css/modules/*.sass, entry sass file (main.sass) is in desktop/css/main.sass

My gulpfile

import gulp from 'gulp'
import sass from 'gulp-sass'
import autoprefixer from 'gulp-autoprefixer'
import cleanCSS from 'gulp-clean-css'
import pug from 'gulp-pug'
import pump from 'pump'
import browserSync from 'browser-sync'

const browserSyncServer = browserSync.create()

gulp.task('desktop-styles', () => {
  gulp.src('desktop/css/*.sass')
    .pipe(sass({ includePaths: ['desktop/css/modules'] }))
    .pipe(autoprefixer())
    .pipe(cleanCSS())
    .pipe(gulp.dest('desktop/build/css'))
    .pipe(browserSyncServer.stream())
})

gulp.task('desktop-html', () => {
  gulp.src('desktop/templates/*.pug')
    .pipe(pug())
    .pipe(gulp.dest('desktop/build'))
    .pipe(browserSyncServer.stream())
})

gulp.task('desktop', ['desktop-html', 'desktop-styles'], () => {
  browserSyncServer.init({
    server: "./desktop/build"
  })
  gulp.watch('desktop/templates/*.pug', ['desktop-html']).on('change', (e) => {
    console.log(` HTML File ${e.path} has been ${e.type}`)
  })
  gulp.watch('desktop/css/*.sass', ['desktop-styles']).on('change', (e) => {
    console.log(` CSS File ${e.path} has been ${e.type}`)
  })
}) 

Upvotes: 0

Views: 300

Answers (1)

zaebalo
zaebalo

Reputation: 157

Oops, problem was in watch method: I watched only .sass files in desktop/css folder, where is main.sass file only. Same with a pug. Hope it will help someone.

Upvotes: 0

Related Questions