Answer the question
In order to leave comments, you need to log in
Gulp doesn't track changes in .html and .css files?
Good afternoon. Can you please tell me where I could be wrong?
I want to follow the changes in .css and .html and do hot reload when saving
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var paths = {
css: ['./style/*.css'],
html: ['./*.html']
};
gulp.task('serve', function () {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: "./"
}
});
gulp.watch(paths.css, paths.html).on("change", reload);
});
'use strict';
const gulp = require('gulp');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
gulp.task('serve', function () {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: "./"
}
});
gulp.watch("*.html").on("change", reload);
});
Answer the question
In order to leave comments, you need to log in
gulp.watch(paths.css, paths.html)
You passed two different arguments, but you need one.
Try
gulp.watch(['./path/to/styles/*/**.*.css ', './path/to/html/*/**.*html'])
On good you should have 2 folders src and dist (for example). In src we have the source codes for html, sass, js, etc., and in dist we have a ready-made project (build).
In your case, create a src folder in the project folder and transfer the html and css files there (Also check the file paths). As needed, just add the migration and compilation to the dist folder.
PS Name the html file index.html, if it is different, then add the parameter "index: Name_of_your_file.html"
'use strict';
const gulp = require('gulp'),
var browserSync = require('browser-sync'),
var reload = browserSync.reload;
// BrowserSync
gulp.task('serve', function () {
browserSync({
server: {
baseDir: "src"
//index: "paths.html" если название нестандартное
},
notify: false
});
});
// Watch
gulp.task('watch', function() {
gulp.watch('./src/css/**/*.css', reload),
gulp.watch('./src/*.html', reload);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question