If you already have a development environment setup with your project (XAMPP, MAMP, WAMP, Vagrant or any other virtual host), you’ll have to use browsersync’s proxy setting.
I made it work with Gulp + SASS + BrowserSync + MAMP + Wordpress. The process for Kirby would be the same, except your watched folders will probably change. Here’s my current gulpfile.js. It has a lot more than just SASS & BrowserSync, but we’ll concentrate on those.
What we’re trying to do is run BrowserSync and watch for changes in the SASS folder, compile the SASS when changes are detected and reload the styles/browser. We also want to watch for changes in .php files.
First off, make sure you load and create an instance of BrowserSync.
var browserSync = require('browser-sync').create();
I assume you’re using an virtual host to run your Kirby install and you already have a gulpwatch task setup for your sass compilation. BrowserSync by default serves your content in it’s own virtual host, however it doesn’t come with PHP. We want to use our existing environment (XAMPP, MAMP, WAMP, Vagrant or any other virtual host) to serve Kirby and use BrowserSync on top of that.
Here’s my watch task. The principle is the same, except you should use your folder structure.
Essentially you’re initializing BrowserSync at the start of your watch task and reloading the browser when .php files are changed.
injectChanges: true makes it possible to change styles and scripts on the fly without reloading the whole makes. It’s slightly faster than reloading. To use this feature, you need to tell BrowserSync to stream the new content within the appropriate tasks.
Thank you so much for this. Now I have a working dev environment with gulp. I have one new issue though, my panel keeps going back to the login page every now and then. This does not happen when I’m not using browser-sync to proxy my server. After I implemented gulp with browser-sync, my kirby panel keeps going back to the login page. Everything works though, it’s just annoying when adding some posts.
Thank you again.
Hi, we have made and are using this for working with a friend: https://github.com/julien-gargot/kirby-devkit.
The master branch is more up-to-date, but the others will be too as soon as possible
Hi, I’m @julieng 's friend who is contributing to the kirby devkit.
I also have the panel issue with browsersync that @sicnarf described.
Here is the github issue I filled about it, maybe this will help with understanding the origin ??
Tracked the bug a bit more :
Everytime I login and modify a page, browsersync says in its output : [BS] File changed: site/accounts/louis.php
but if I disable the path in bold in the browsersync task, panel login stays operational and I am not getting this message anymore : browserSync.init({ files: [**'{site}/**/*.php'**, '*.php', userScripts, 'assets/less/*.less'], proxy: localDevUrl, });
So what I think is happening is that somehow browersync watching an account’s files is logging out a user.
A user in the Kirby forum has suggested to use and ignorePaths (see Kirby + Gulp + Browsersync + Sass - #5 by julieng) and I tried setting ‘site/accounts/**’ as an ignore path but it’s not working.
Thanks @PaulMorel, this is working just fine.
The panel is now acting normal and keeping me logged in as usual. I just updated the devkit with this fix.
In the future, pls. enclose blocks of code with three backticks at the beginning and at the end of your code block, this will highlight your code and make it much more readable. Thank you.
I’m running the exact same setup and have a similar but not exactly identical issue. The panel logs me out not when I’m changing any file but when I’m navigation to another page in the frontend.
@sicnarf If you’re still running this setup, do you have the same issue?
I am also still encountering the same issue, I can’t seem to fix it. Could anyone show your working gulpfile, which browsersync doesn’t make you log out of the panel whenever you navigate on another page/ change any files?
Here is mine, which is causing me problems: gulpfile.js
I’ve set my MAMP to *.dev now and use browserSync on localhost. That way it works. It may not be that convenient, since you can’t use multiple instances but it’s better than logging in every minute.
Here’s my current task for the gulp browsersync.
It does logout from time to time but not the same as before that every edit I make logs me out. As suggested above I added the option “ignorePaths”.
My current best solution was to use safari for my panel, and chrome for the front-end.
// ////////////////////////////////////////////////
// Server
// ////////////////////////////////////////////////