При запуске gulp watch появляется ошибка
[error] You tried to start Browsersync twice! To create multiple instances, use browserSync.create().init()
gulp watch обновляет страницу, но через раз
gulpfile:
var gulp = require('gulp'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
clean = require('gulp-clean'),
rename = require('gulp-rename'),
pug = require('gulp-pug'),
copy = require('gulp-copy'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
imagemin = require('gulp-imagemin');
gulp.task('sass', function(){
gulp.src(['app/scss/*.scss','!app/scss/includeFonts.scss'])
.pipe(sass())
.pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], {cascade: true}))
.pipe(concat('style.css'))
.pipe(gulp.dest('dist/style/'))
.pipe(browserSync.reload({stream: true}))
});
gulp.task('pug', function(){
return gulp.src ('app/*.pug')
.pipe(pug({pretty:true}))
.pipe(gulp.dest('dist'))
.pipe(browserSync.reload({stream: true}))
});
gulp.task('fonts', function(){
gulp.src('app/scss/includeFonts.scss')
.pipe(sass())
.pipe(concat('fonts.css'))
.pipe(gulp.dest('dist/style/'))
});
gulp.task('clean', function () {
return gulp.src(['dist/scripts/libs.js', 'dist/style/libs.css'], {read: false})
.pipe(clean());
});
gulp.task('buildConfigJs', function(){
return gulp.src(['bower_components/*/dist/**/*.min.js','!bower_components/*/dist/**/*.slim.min.js'])
.pipe(concat('libs.js'))
.pipe(gulp.dest('dist/scripts/'));
});
gulp.task('buildConfigCss', function(){
return gulp.src('bower_components/*/dist/**/*.min.css')
.pipe(concat('libs.css'))
.pipe(gulp.dest('dist/style/'));
});
gulp.task('buildConfig', ['buildConfigCss','buildConfigJs'])
// gulp.task('buildCss', function(){
// return gulp.src('app/css/*.css')
// .pipe(concat('style.css'))
// .pipe(gulp.dest('dist/style/'))
// });
gulp.task('buildJs', function(){
return gulp.src('app/js/*.js')
.pipe(concat('main.js'))
.pipe(gulp.dest('dist/scripts/'))
.pipe(browserSync.reload({stream: true}))
});
gulp.task('imgCopy',function(){
return gulp.src('app/images/*.*')
.pipe(imagemin())
.pipe(gulp.dest('dist/images'))
});
gulp.task('fontsCopy',function(){
return gulp.src('app/fonts/*.*')
.pipe(gulp.dest('dist/fonts'))
});
gulp.task('build', ['sass','buildJs','imgCopy','pug','fontsCopy']);
gulp.task('browser-sync', function(){
browserSync({
server :{
baseDir: 'dist'
},
browser: 'chrome'
});
});
gulp.task('watch', ['browser-sync', 'sass', 'pug', 'buildJs','fonts'], function () {
gulp.watch('app/**/*.scss', [sass]);
gulp.watch('app/**/*.pug', [pug]);
gulp.watch('app/**/*.js', ['buildJs']);
});
package.js
{
"name": "kdd",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Andrey Denisov",
"license": "ISC",
"description": "",
"devDependencies": {
"browser-sync": "^2.24.5",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^5.0.0",
"gulp-clean": "^0.4.0",
"gulp-copy": "^1.1.0",
"gulp-imagemin": "^4.1.0",
"gulp-pug": "^4.0.1",
"gulp-rename": "^1.3.0",
"gulp-sass": "^4.0.1"
},
"dependencies": {
"bower-canary": "^1.3.0",
"gulp-concat": "^2.6.1",
"gulp-jquery": "^1.1.2"
}
}