Answer the question
In order to leave comments, you need to log in
How to add gulp 4?
Good afternoon.
There is an app.js like this:
const express = require("express");
const app = express();
var pageInfo = {
home: {
link: "/",
title: "Main page",
description: "Some text"
}
};
app.set("view engine", "pug");
app.use("/public/", express.static(__dirname + "/static/"));
app.use("/", function(request, response){
response.render("home.pug", {
meta: pageInfo.home
});
});
app.get("*", function(request, response){
response.sendStatus("404");
});
app.listen(3000);
const { src, dest, watch, series } = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const minifyCss = require('gulp-minify-css');
const browserSync = require('browser-sync').create();
function cssCompile(){
return src('static/sass/**/*.s?ss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
overrideBrowserslist: ['last 10 versions'],
cascade: false
}))
.pipe(minifyCss({
compatibility: 'ie8'
}))
.pipe(dest('static/css/'))
.pipe(browserSync.reload({stream: true}));
}
function server(done){
browserSync.init({
server: {
baseDir: '/'
},
notify: false
});
watch('static/sass/**/*.s?ss', cssCompile);
done();
}
exports.cssCompile = cssCompile;
exports.server = server;
exports.default = series(cssCompile, server);
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then you need to make sure that when changing files, the project is rebuilt and the result is displayed in the browser.
To do this, you need to use gulp.watch (), which just watches for changes in files and, depending on their type / other conditions, launches the necessary task.
Once the rebuild task is complete, browsersync will refresh the page for you.
Here is an example .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question