Has anyone managed to get gulp browsersync or livereload to work with Local version 2.1.1 (update added ‘connect to flywheel’). In my case, the gulp tasks are running fine, but the browser does not reload in the watch task. It’s driving me nuts. Please help!
may I ask if the tasks work as expected when being run independently? For example, if you run gulp styles are the styles correctly processed and copied to styleDesitnation and show up when you manually refresh http://custom.dev?
Are you using the browsersync url for development? When my proxy points to http://philipp.dev I have to use http://127.0.0.1:3000 (this url gets outputted by gulp in the console) in order to get browsersync functionality.
I’ve created a small prototype to see where things go wrong. Seems that your gulpfile.js is not working correctly. Following findings:
There is no reload task, hence your browser doesn’t show anything other than a blank page. That got me thinking and I did a very brief rewrite of your gulpfile.js and concentrated on the styles only. As the saying goes: It works on my machine (-:
var projectURL = 'http://playground.local'; // Local project URL of your already running WordPress site. Could be something like local.dev or localhost:8888.
var styleSRC = 'scss/style.scss'; // Path to main .scss file.
var styleDestination = ''; // Path to place the compiled CSS file.
var jsSRC = 'js/vendor/*.js'; // Path to all vendor JS files.
var jsDestination = 'js/vendor/'
// Watch files paths.
var styleWatchFiles = 'scss/**/*.scss'; // Path to all *.scss files inside css folder and inside them.
// Load plugins
var gulp = require('gulp');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
gulp.task('styles', function () {
return gulp.src(styleSRC)
.pipe(sass({
errLogToConsole: true,
outputStyle: 'compact',
precision: 10
}))
.on('error', console.error.bind(console))
.pipe(gulp.dest(styleDestination))
.pipe(browserSync.stream({match: '**/*.css'})) // Reloads style.css if that is enqueued.
});
gulp.task('js-stuff', function () {
// HINT: here you would place all of your js related tasks, e.g. minification
return gulp.src(jsSRC)
.pipe(gulp.dest(jsDestination));
});
gulp.task('reload-js', ['js-stuff'], function (done) {
browserSync.reload();
done();
});
gulp.task('watch', function () {
gulp.watch(styleWatchFiles, ['styles']); // Reload on SCSS file changes.
gulp.watch(['src/js/**/*'], ['reload-js']);
});
gulp.task('default', [
'styles',
'watch'
], function () {
browserSync.init({
proxy: projectURL,
open: true
});
});
Maybe that helps in debugging the error on your side.
Late to the party here — developer of WPGulp (I think it’s the most popular gulp utility for WordPress). Take a look and use it. BrowserSync works just fine with local and WPGulp.
Hi Mark, just curious, does this setup work if you go to an internal page and make changes to your css or php files? I’m using an automation setup that works only in the front-page.php file. Thank you.