Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with gulpfile.js in Wordpress

Featured Replies

Hello all

I have created a gulpfile which I want to watch for any changes to PHP and SCSS files.

When I run the gulp command in the terminal, Browser-sync starts up and the page is displayed fine.  It also says it is watching files. If I try to edit a PHP or SCSS file in the terminal it says [Browsersync] Reloading Browsers..., but nothing happens.

I want the SCSS to compile directly into the theme folder I have created and overwrite the style.css. I also want any changes I make to a PHP file to reload the broswer.

My gulpfile is as follows:

// Include gulp
const gulp = require('gulp');

// Include plugins
const concat = require('gulp-concat'),
	autoprefixer = require('gulp-autoprefixer'),
	sass = require('gulp-sass'),
	sourcemaps = require('gulp-sourcemaps'),
	browserSync = require('browser-sync').create(),
	reload = browserSync.reload;

gulp.task('sass', function () {
	return sass('./assets/sass/style.scss', { sourcemap: true, style: 'compressed' })
		.on('error', sass.logError)
		.pipe(autoprefixer())
		.pipe(sourcemaps.write('.', {
			includeContent: false
		}))
		.pipe(gulp.dest('.'));
});

gulp.task('browser-sync', function () {
	var files = [
		'./*.php',
		'./template-parts/*.php',
		'./inc/*.php',
		'./assets/**/*.scss',
		'style.css'
	];

	// Initialises browserSync
	browserSync.init(files, {
		proxy: "http://localhost/test/",
		notify: false
	});
});

// Watch for changes in files
gulp.task('watch', function () {
	// Watch .scss files
	gulp.watch('./assets/**/*.scss', ['sass']);
});

// Default task to compile css
gulp.task('default', ['sass', 'browser-sync'], function () {
	gulp.watch('./assets/**/*.scss', ['sass']);
});

Any help would be greatly appreciated.

On 8/11/2018 at 1:44 PM, predatorx said:

Hello all

I have created a gulpfile which I want to watch for any changes to PHP and SCSS files.

When I run the gulp command in the terminal, Browser-sync starts up and the page is displayed fine.  It also says it is watching files. If I try to edit a PHP or SCSS file in the terminal it says [Browsersync] Reloading Browsers..., but nothing happens.

I want the SCSS to compile directly into the theme folder I have created and overwrite the style.css. I also want any changes I make to a PHP file to reload the broswer.

My gulpfile is as follows:


// Include gulp
const gulp = require('gulp');

// Include plugins
const concat = require('gulp-concat'),
	autoprefixer = require('gulp-autoprefixer'),
	sass = require('gulp-sass'),
	sourcemaps = require('gulp-sourcemaps'),
	browserSync = require('browser-sync').create(),
	reload = browserSync.reload;

gulp.task('sass', function () {
	return sass('./assets/sass/style.scss', { sourcemap: true, style: 'compressed' })
		.on('error', sass.logError)
		.pipe(autoprefixer())
		.pipe(sourcemaps.write('.', {
			includeContent: false
		}))
		.pipe(gulp.dest('.'));
});

gulp.task('browser-sync', function () {
	var files = [
		'./*.php',
		'./template-parts/*.php',
		'./inc/*.php',
		'./assets/**/*.scss',
		'style.css'
	];

	// Initialises browserSync
	browserSync.init(files, {
		proxy: "http://localhost/test/",
		notify: false
	});
});

// Watch for changes in files
gulp.task('watch', function () {
	// Watch .scss files
	gulp.watch('./assets/**/*.scss', ['sass']);
});

// Default task to compile css
gulp.task('default', ['sass', 'browser-sync'], function () {
	gulp.watch('./assets/**/*.scss', ['sass']);
});

Any help would be greatly appreciated.

Your watch task only appears to be watching for Sass files.

Edited by rbrtsmith

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.