-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does gulp-livereload work with Gulp 4? #138
Comments
Not sure if you still need help with this. Attaching my current gulpfile.js in case it helps anyone :) // package vars
const pkg = require("./package.json");
// gulp
const gulp = require("gulp");
// load all plugins in "devDependencies" into the variable _f
const _f = require("gulp-load-plugins")({
pattern: ["*"],
scope: ["devDependencies"]
});
const onError = (err) => {
console.log(err);
};
const banner = [
"/**",
" * @project <%= pkg.name %>",
" * @author <%= pkg.author %>",
" * @build " + _f.moment().format("llll") + " ET",
// " * @release " + _f.gitRevSync.long() + " [" + _f.gitRevSync.branch() + "]",
" * @copyright Copyright (c) " + _f.moment().format("YYYY") + ", <%= pkg.copyright %>",
" *",
" */",
""
].join("\n");
// scss - build the scss to the build folder, including the required paths, and writing out a sourcemap
gulp.task("scss", () => {
_f.fancyLog("-> Compiling scss");
return gulp.src(pkg.paths.src.css + pkg.vars.scssName, { allowEmpty: true })
.pipe(_f.plumber({errorHandler: onError}))
.pipe(_f.sassGlob())
.pipe(_f.sourcemaps.init({loadMaps: true}))
.pipe(_f.sass({
includePaths: pkg.paths.scss
})
.on("error", _f.sass.logError))
.pipe(_f.cached("sass_compile"))
.pipe(_f.autoprefixer(
{
browsers: ['last 2 versions', 'iOS >= 8']
}
))
.pipe(_f.sourcemaps.write("./"))
.pipe(_f.size({gzip: true, showFiles: true}))
.pipe(gulp.dest(pkg.paths.build.css));
});
// css task - combine & minimize any distribution CSS into the public css folder, and add our banner to it
gulp.task("css", gulp.series("scss", () => {
_f.fancyLog("-> Building css");
return gulp.src([pkg.paths.build.css + "**/*.css", "!"+ pkg.paths.dist.css + "**/*"], { allowEmpty: true })
.pipe(_f.plumber({errorHandler: onError}))
.pipe(_f.print.default())
.pipe(_f.sourcemaps.init({loadMaps: true}))
.pipe(_f.concat(pkg.vars.cssName))
.pipe(_f.cssnano({
discardComments: {
removeAll: true
},
discardDuplicates: true,
discardEmpty: true,
minifyFontValues: true,
minifySelectors: true
}))
.pipe(_f.header(banner, {pkg: pkg}))
.pipe(_f.sourcemaps.write("./"))
.pipe(_f.size({gzip: true, showFiles: true}))
.pipe(gulp.dest(pkg.paths.dist.css))
.pipe(_f.filter("**/*.css"))
.pipe(_f.livereload());
}));
// js task
gulp.task("js", () => {
_f.fancyLog("-> Building js");
return gulp.src([pkg.paths.src.js + "**/*.js", "!"+ pkg.paths.dist.js + "**/*"], { allowEmpty: true })
.pipe(_f.plumber({errorHandler: onError}))
.pipe(_f.concat(pkg.vars.jsName))
.pipe(_f.uglify())
.pipe(_f.header(banner, {pkg: pkg}))
.pipe(_f.size({gzip: true, showFiles: true}))
.pipe(gulp.dest(pkg.paths.dist.js))
.pipe(_f.filter("**/*.js"))
.pipe(_f.livereload());
});
// Default task
gulp.task("default", gulp.series( "css", "js", () => {
_f.livereload.listen();
gulp.watch([pkg.paths.src.css + "**/*.scss", "!"+ pkg.paths.dist.css + "**/*"], gulp.series("css"));
gulp.watch([pkg.paths.src.js + "**/*.js", "!"+ pkg.paths.dist.js + "**/*"], gulp.series("js"));
})); |
Use same. like gulp@3
|
I'm also having issues. Gulp 3.9.1 works just fine for me but not 4.0.0. It detects changes just fine when I edit a watched file via SSH (using Vagrant with Ubuntu 18.04) in a text editor, but no longer will it detect changes if I update a watched via my host in a synced folder. Simplest example I can produce: `const gulp = require('gulp'), gulp.task('watch', function(done){ Loads fine, and again, it detects changes when I make changes to a watched when I SSH into the Vagrant box, but no longer when I edit a file locally on my host machine outside of the Vagrant environment. Works totally fine when I revert Gulp to 3.9.1. |
Update: the same behavior occurs when I tried browsersync, so obviously this is not a livereload problem, it appears to be an issue with Gulp 4.0. |
I've tried browsersync in the past and found it to be too heavyweight for what I wanted to do. I'm doing a pretty simple SCSS, and vanilla HTML/JS project and I'm having trouble getting livereload to work. I've installed the chrome extension and it seems to be giving a "reloaded" message but it's not actually reloading the webpage I'm working on (or any other from what I can see). Here's my gulpfile if anyone has any ideas. I'm using gulp 4 also:
And here's a sample of my gulp cli readout:
|
For me to work, I had to separate the default and watch task and also call the tasks with gulp.series() Before:
After
|
For the .reload() method used to refresh the page, I found I had to use it in an async function after updating to Gulp 4: gulp.watch(phpFiles, async () => livereload.reload() ); where php files is the directory to watch |
I actually recently fixed this issue for myself. If it would help anyone here is a link to my gulp file: https://github.com/jcklpe/common-wp-theme/blob/master/gulpfile.js And here is it's contents.
|
I haven't had any luck getting gulp-livereload to work with Gulp 4. I also don't see any Gulp 4 examples in the README.md.
The text was updated successfully, but these errors were encountered: