BrowserSync (via Gulp) is crashing after a while, especially when I change the .twig files











up vote
0
down vote

favorite












Problem:
I am running Gulp 3.9.1 with BrowserSync 2.26.3. Everything works fine when I compile SASS and JS files. But after awhile, when I make changes to the Twig files BrowserSync stops working and remain stuck, displaying the message: "Reloading Browsers…".



Temporary Solution:
I need to restart the default gulp task again to make it work. Here is gulpfile



var gulp            = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify-es').default,
browserSync = require('browser-sync').create(),
plumber = require('gulp-plumber');
Promise = require('es6-promise').Promise;
jquery = require("jquery");

var projectName = 'MYPROJECTNAME';

var paths = {
twig: 'wp-content/themes/' + projectName + '/views/**/*.twig',
php: 'wp-content/themes/' + projectName + '/**/*.php',
yml: 'wp-content/themes/' + projectName + '/**/*.yml',
sass: 'wp-content/themes/' + projectName + '/scss/**/*.scss',
js: 'wp-content/themes/' + projectName + '/js/**/*.js',
cssOutputRoot: 'wp-content/themes/' + projectName + '',
cssOutput: 'wp-content/themes/' + projectName + '',
jsOutput: 'wp-content/themes/' + projectName + ''
};

var jsFiles = [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/foundation-sites/dist/js/foundation.min.js',
'wp-content/themes/' + projectName + '/js/app.js'
];

var sassFiles = [
'wp-content/themes/' + projectName + '/scss/style.scss'
];

gulp.task('css', function () {
gulp.src(sassFiles)
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(concat('style.css'))
.pipe(gulp.dest(paths.cssOutputRoot))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('js', function() {
gulp.src(jsFiles)
.pipe(plumber(function(error){
console.log("Error happend!", error.message);
this.emit('end');
}))
.pipe(uglify())
.pipe(concat('app.js'))
.pipe(gulp.dest(paths.jsOutput))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('browserSync', function() {
browserSync.init({
proxy: 'localhost/' + projectName,
notify: false
});
});

gulp.task('default', ['browserSync','css','js'], function() {
gulp.watch(paths.sass, ['css']);
gulp.watch(paths.js, ['js']);
gulp.watch(paths.twig, browserSync.reload);
gulp.watch(paths.php, browserSync.reload);
gulp.watch(paths.yml, browserSync.reload);
});









share|improve this question






















  • First thing to try is adding a return statement to all your tasks, like return gulp.src(……..
    – Mark
    Nov 8 at 2:33















up vote
0
down vote

favorite












Problem:
I am running Gulp 3.9.1 with BrowserSync 2.26.3. Everything works fine when I compile SASS and JS files. But after awhile, when I make changes to the Twig files BrowserSync stops working and remain stuck, displaying the message: "Reloading Browsers…".



Temporary Solution:
I need to restart the default gulp task again to make it work. Here is gulpfile



var gulp            = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify-es').default,
browserSync = require('browser-sync').create(),
plumber = require('gulp-plumber');
Promise = require('es6-promise').Promise;
jquery = require("jquery");

var projectName = 'MYPROJECTNAME';

var paths = {
twig: 'wp-content/themes/' + projectName + '/views/**/*.twig',
php: 'wp-content/themes/' + projectName + '/**/*.php',
yml: 'wp-content/themes/' + projectName + '/**/*.yml',
sass: 'wp-content/themes/' + projectName + '/scss/**/*.scss',
js: 'wp-content/themes/' + projectName + '/js/**/*.js',
cssOutputRoot: 'wp-content/themes/' + projectName + '',
cssOutput: 'wp-content/themes/' + projectName + '',
jsOutput: 'wp-content/themes/' + projectName + ''
};

var jsFiles = [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/foundation-sites/dist/js/foundation.min.js',
'wp-content/themes/' + projectName + '/js/app.js'
];

var sassFiles = [
'wp-content/themes/' + projectName + '/scss/style.scss'
];

gulp.task('css', function () {
gulp.src(sassFiles)
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(concat('style.css'))
.pipe(gulp.dest(paths.cssOutputRoot))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('js', function() {
gulp.src(jsFiles)
.pipe(plumber(function(error){
console.log("Error happend!", error.message);
this.emit('end');
}))
.pipe(uglify())
.pipe(concat('app.js'))
.pipe(gulp.dest(paths.jsOutput))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('browserSync', function() {
browserSync.init({
proxy: 'localhost/' + projectName,
notify: false
});
});

gulp.task('default', ['browserSync','css','js'], function() {
gulp.watch(paths.sass, ['css']);
gulp.watch(paths.js, ['js']);
gulp.watch(paths.twig, browserSync.reload);
gulp.watch(paths.php, browserSync.reload);
gulp.watch(paths.yml, browserSync.reload);
});









share|improve this question






















  • First thing to try is adding a return statement to all your tasks, like return gulp.src(……..
    – Mark
    Nov 8 at 2:33













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Problem:
I am running Gulp 3.9.1 with BrowserSync 2.26.3. Everything works fine when I compile SASS and JS files. But after awhile, when I make changes to the Twig files BrowserSync stops working and remain stuck, displaying the message: "Reloading Browsers…".



Temporary Solution:
I need to restart the default gulp task again to make it work. Here is gulpfile



var gulp            = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify-es').default,
browserSync = require('browser-sync').create(),
plumber = require('gulp-plumber');
Promise = require('es6-promise').Promise;
jquery = require("jquery");

var projectName = 'MYPROJECTNAME';

var paths = {
twig: 'wp-content/themes/' + projectName + '/views/**/*.twig',
php: 'wp-content/themes/' + projectName + '/**/*.php',
yml: 'wp-content/themes/' + projectName + '/**/*.yml',
sass: 'wp-content/themes/' + projectName + '/scss/**/*.scss',
js: 'wp-content/themes/' + projectName + '/js/**/*.js',
cssOutputRoot: 'wp-content/themes/' + projectName + '',
cssOutput: 'wp-content/themes/' + projectName + '',
jsOutput: 'wp-content/themes/' + projectName + ''
};

var jsFiles = [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/foundation-sites/dist/js/foundation.min.js',
'wp-content/themes/' + projectName + '/js/app.js'
];

var sassFiles = [
'wp-content/themes/' + projectName + '/scss/style.scss'
];

gulp.task('css', function () {
gulp.src(sassFiles)
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(concat('style.css'))
.pipe(gulp.dest(paths.cssOutputRoot))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('js', function() {
gulp.src(jsFiles)
.pipe(plumber(function(error){
console.log("Error happend!", error.message);
this.emit('end');
}))
.pipe(uglify())
.pipe(concat('app.js'))
.pipe(gulp.dest(paths.jsOutput))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('browserSync', function() {
browserSync.init({
proxy: 'localhost/' + projectName,
notify: false
});
});

gulp.task('default', ['browserSync','css','js'], function() {
gulp.watch(paths.sass, ['css']);
gulp.watch(paths.js, ['js']);
gulp.watch(paths.twig, browserSync.reload);
gulp.watch(paths.php, browserSync.reload);
gulp.watch(paths.yml, browserSync.reload);
});









share|improve this question













Problem:
I am running Gulp 3.9.1 with BrowserSync 2.26.3. Everything works fine when I compile SASS and JS files. But after awhile, when I make changes to the Twig files BrowserSync stops working and remain stuck, displaying the message: "Reloading Browsers…".



Temporary Solution:
I need to restart the default gulp task again to make it work. Here is gulpfile



var gulp            = require('gulp'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify-es').default,
browserSync = require('browser-sync').create(),
plumber = require('gulp-plumber');
Promise = require('es6-promise').Promise;
jquery = require("jquery");

var projectName = 'MYPROJECTNAME';

var paths = {
twig: 'wp-content/themes/' + projectName + '/views/**/*.twig',
php: 'wp-content/themes/' + projectName + '/**/*.php',
yml: 'wp-content/themes/' + projectName + '/**/*.yml',
sass: 'wp-content/themes/' + projectName + '/scss/**/*.scss',
js: 'wp-content/themes/' + projectName + '/js/**/*.js',
cssOutputRoot: 'wp-content/themes/' + projectName + '',
cssOutput: 'wp-content/themes/' + projectName + '',
jsOutput: 'wp-content/themes/' + projectName + ''
};

var jsFiles = [
'node_modules/jquery/dist/jquery.min.js',
'node_modules/foundation-sites/dist/js/foundation.min.js',
'wp-content/themes/' + projectName + '/js/app.js'
];

var sassFiles = [
'wp-content/themes/' + projectName + '/scss/style.scss'
];

gulp.task('css', function () {
gulp.src(sassFiles)
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(autoprefixer())
.pipe(concat('style.css'))
.pipe(gulp.dest(paths.cssOutputRoot))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('js', function() {
gulp.src(jsFiles)
.pipe(plumber(function(error){
console.log("Error happend!", error.message);
this.emit('end');
}))
.pipe(uglify())
.pipe(concat('app.js'))
.pipe(gulp.dest(paths.jsOutput))
.pipe(browserSync.reload({
stream: true
}));
});

gulp.task('browserSync', function() {
browserSync.init({
proxy: 'localhost/' + projectName,
notify: false
});
});

gulp.task('default', ['browserSync','css','js'], function() {
gulp.watch(paths.sass, ['css']);
gulp.watch(paths.js, ['js']);
gulp.watch(paths.twig, browserSync.reload);
gulp.watch(paths.php, browserSync.reload);
gulp.watch(paths.yml, browserSync.reload);
});






gulp twig browser-sync






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 7 at 9:10









Lukas Hillebrand

108110




108110












  • First thing to try is adding a return statement to all your tasks, like return gulp.src(……..
    – Mark
    Nov 8 at 2:33


















  • First thing to try is adding a return statement to all your tasks, like return gulp.src(……..
    – Mark
    Nov 8 at 2:33
















First thing to try is adding a return statement to all your tasks, like return gulp.src(……..
– Mark
Nov 8 at 2:33




First thing to try is adding a return statement to all your tasks, like return gulp.src(……..
– Mark
Nov 8 at 2:33

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186386%2fbrowsersync-via-gulp-is-crashing-after-a-while-especially-when-i-change-the%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186386%2fbrowsersync-via-gulp-is-crashing-after-a-while-especially-when-i-change-the%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings