Answer the question
In order to leave comments, you need to log in
How to automatically recompile the main styles file in GULP when changing any style files?
There is a task in gulp responsible for working with style files, I give it below:
// config.json
{
***
"scss": {
"dev": {
"src": ["./src/app/css_source/**/*.scss", "!./src/app/css_source/res/", "!./src/app/css_source/res/**/*"],
"dest": "./src/app/css/"
}
}
***
}
// css.js
"use strict";
const config = require("../config.json");
const gulp = require("gulp");
const watch = require("gulp-watch");
const browserSync = require("browser-sync");
const sass = require("gulp-sass");
const autoprefixer = require("gulp-autoprefixer");
const sourcemaps = require("gulp-sourcemaps");
const conf = {};
conf.src = config.scss.dev.src;
conf.dest = config.scss.dev.dest;
conf.autopref_config = config.autoprefixer;
const cssTask = () => {
return gulp.src(conf.src)
.pipe(watch(conf.src))
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoprefixer(conf.autopref_config))
.pipe(sourcemaps.write())
.pipe(gulp.dest(conf.dest))
.pipe(browserSync.stream());
};
gulp.task("css", cssTask);
module.exports = cssTask;
Answer the question
In order to leave comments, you need to log in
Found the answer to my question. For those who are interested, here is my solution. The option is naevrnoe such itself and needs to be improved, but better than it was.
// css.js
const cssTask = () => {
return gulp.watch(conf.src).on("change", () => {
return gulp.src("./src/app/css_source/main.scss")
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(autoprefixer(conf.autopref_config))
.pipe(sourcemaps.write())
.pipe(gulp.dest(conf.dest))
.pipe(browserSync.stream());
});
};
in general, with such a config, it should already recompile when it changes, because src points to all .scss, not only to main.
I sometimes have the same thing with yeo-yeogurt. It compiles when any file changes, but if you add a new import to main.scss , it stops compiling files that fall under the /**/*.scss regular expression and starts recompiling only when main is resaved. Only restarting the task helps in this case.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question