Всем привет! Подскажите пожалуйста, почему не срабатывает обновление страницы прис хранении pug файлов и stylus?
var gulp = require('gulp'),
browsersync = require('browser-sync'),
reload = browsersync.reload,
spritesmith = require("gulp.spritesmith"),
pugInheritance = require('gulp-pug-inheritance'),
pug = require('gulp-pug'),
changed = require('gulp-changed'),
cached = require('gulp-cached'),
gulpif = require('gulp-if'),
filter = require('gulp-filter'),
stylus = require('gulp-stylus'),
sourcemaps = require('gulp-sourcemaps'),
csscomb = require('gulp-csscomb'),
plumber = require("gulp-plumber"),
notify = require("gulp-notify"),
autoprefixer = require('gulp-autoprefixer');
// PUG
gulp.task('pug', function() {
return gulp.src('dev/pug/**/*.pug')
//only pass unchanged *main* files and *all* the partials
.pipe(changed('dist', { extension: '.html' }))
//filter out unchanged partials, but it only works when watching
.pipe(gulpif(global.isWatching, cached('pug')))
//find files that depend on the files that have changed
.pipe(pugInheritance({ basedir: 'dev/pug/', extension: '.pug', skip: 'node_modules' }))
//filter out partials (folders and files starting with "_" )
.pipe(filter(function(file) {
return !/\/_/.test(file.path) && !/^_/.test(file.relative);
}))
.pipe(plumber())
.pipe(pug())
.on("error", notify.onError(function(error) {
return "Message to the notifier: " + error.message;
}))
.pipe(gulp.dest('dist'));
});
gulp.task('setWatch', function() {
global.isWatching = true;
});
// STYLUS
gulp.task('stylus', function() {
return gulp.src('dev/static/stylus/*.styl')
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(stylus({
'include css': true,
compress: true
}))
.on("error", notify.onError(function(error) {
return "Message to the notifier: " + error.message;
}))
.pipe(autoprefixer(['last 2 version']))
.pipe(sourcemaps.write('.'))
.pipe(csscomb())
.pipe(gulp.dest('dist/static/css/'))
.pipe(reload({
stream: true
}));
});
// СЕРВЕР
gulp.task('browsersync', function() {
browsersync.init({
server: {
baseDir: 'dist'
},
});
});
// Сборка спрайтов PNG
gulp.task('cleansprite', function() {
return del.sync('dev/static/img/sprite/sprite.png');
});
gulp.task('spritemade', function() {
var spriteData =
gulp.src('dev/static/img/sprite/*.*')
.pipe(spritesmith({
imgName: 'sprite.png',
cssName: '_sprite.styl',
padding: 10,
cssFormat: 'stylus',
algorithm: 'binary-tree',
cssTemplate: 'stylus.template.mustache',
cssVarMap: function(sprite) {
sprite.name = 's-' + sprite.name;
}
}));
spriteData.img.pipe(gulp.dest('dev/static/img/sprite/')); // путь, куда сохраняем картинку
spriteData.css.pipe(gulp.dest('dev/static/stylus/')); // путь, куда сохраняем стили
});
gulp.task('sprite', ['cleansprite', 'spritemade']);
// СЛЕЖКА
gulp.task('watch', ['browsersync', 'stylus'], function() {
gulp.watch('dev/static/stylus/**/*.styl', ['stylus']);
gulp.watch('dev/pug/*.pug', ['pug']);
gulp.watch('dist/*.html', browsersync.reload);
});
// Дефолтный таск
gulp.task('default', ['watch']);
Заранее спасибо
Вопрос задан
более трёх лет назад
831 просмотр