I couldn’t understand exactly what I meant here:
[...] but the server task prevails over the others
You could give an example of what happens today?
But as I understand it, you want when saving the scss file, it will embed Sass and the page will be automatically updated with Browsersync.
My standard gulpfile does it perfectly, see if it works as you expect:
gulpfile.js
var gulp = require('gulp'),
sass = require('gulp-sass'),
prefix = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
notify = require('gulp-notify'),
rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
// Static Server + watching scss/html files
gulp.task('serve', ['compileStyles'], function() {
browserSync.init({
server: "./"
});
var watcher = gulp.watch(["sass/*.{sass,scss}", "scss/**/*.{sass,scss}"], ['compileStyles']);
gulp.watch("*.html").on('change', browserSync.reload);
gulp.watch("js/*.js").on('change', browserSync.reload);
gulp.watch("css/*.css").on('change', browserSync.reload);
watcher.on('change', function(event) {
console.log('SASS/SCSS File ' + event.path + ' was ' + event.type + ', running tasks...');
});
});
function processSass(gulp, file) {
gulp.src('sass/' + file + '.scss')
.pipe(sass().on('error', sass.logError))
.pipe(rename(file + '.css'))
.pipe(gulp.dest('css/'))
.pipe(prefix('last 3 version'));
//.pipe(minifycss());
}
function processScss(gulp, file) {
gulp.src('scss/' + file + '.scss')
.pipe(sass().on('error', sass.logError))
.pipe(rename(file + '.css'))
.pipe(gulp.dest('css/'))
.pipe(prefix('last 3 version'));
//.pipe(minifycss());
}
gulp.task('compileStyles', function() {
processSass(gulp, 'style');
processSass(gulp, 'fonts');
processScss(gulp, 'bootstrap/bootstrap');
gulp.src('./')
.pipe(notify("Arquivos Atualizados com sucesso!"));
browserSync.reload();
});
gulp.task('default', ['serve']);
Thanks for the help Adrian! Your script has many tasks, I just want to use the ones that are in js that I shared. My goal is exactly what you described.
– Munir Baarini
I shared the whole script so that maybe you could use some of it or get the right stream. But I’m glad you were able to solve your problem. :)
– Adrian Matheus Fernandez
Thanks Adrian! Thank you!
– Munir Baarini