Reputation: 157
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:
includePaths in some ways
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
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