A
A
alexeeey_kuznetsov2019-05-27 22:19:50
Sass
alexeeey_kuznetsov, 2019-05-27 22:19:50

How to organize scss compilation, concatenation into one file and browser updates for a multi-page site?

Hello!
I have the following folder structure in my project.
5cec36752fe6c877042118.png
And such a gulp for the main page.

const gulp = require('gulp');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const sourcemaps = require('gulp-sourcemaps');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();


gulp.task('sass', function() {
  return gulp.src('./src/scss/main/*.scss')
  .pipe(sourcemaps.init())
  .pipe(sass())
  .pipe(concat('main.css'))
  .pipe(autoprefixer({
            browsers: ['last 2 versions'],
            cascade: false
        }))
  .pipe(sourcemaps.write())
  .pipe(gulp.dest('./public/css/main/'))
  .pipe(browserSync.stream());
});
gulp.task('serve', function() {
  browserSync.init({
    server: {
      baseDir: './public'
    }
  });
  gulp.watch('./src/scss/**/*.scss', gulp.series('sass'));
  gulp.watch('./public/*.html').on('change', browserSync.reload);
  gulp.watch('./public/js/*.js').on('change', browserSync.reload);
});

gulp.task('default', gulp.series('sass', 'serve'));

The question is that I will add new pages to the project and each one needs its own scss for media and basic styles, and I don’t understand how to write it more competently in gulpfile. Those. when creating a page, for example about, a file should be created in src->scss->about->about.scss to it in the same media.scss folder and after running in the galle they should be connected in concat to a separate folder in a css file in public-> css->about->about.css. And of course, your own js file for each page.
I don’t understand how to minimally write down in a gallp, at best, one task so that the gallp does it all.
Since I am just starting to use gallp, I would simply make several copies of the sass task for each page with an explicit indication of the path to the files, but this is a lot of lines. And perhaps there is a way to do it more concisely and simply.
I'm new to gulp - I hope you understand)
Thanks in advance for your help!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question