D
D
Dmitry Khristoev2016-05-07 14:47:12
atom
Dmitry Khristoev, 2016-05-07 14:47:12

Gulp-jade and 50 templates - how to speed up the build?

Hello! gallp file at the end. Faced the problem of building a project that has more than 50 templates. Some blocks are moved to files.
There are 2 tasks, to build jade, and to run default - jade, browser-sync, watch, etc.
Jade compiles - well.. 20 minutes. default starts in a few seconds, but... the first change in jade also compiles for 10-20 minutes, then, after the first time, it happens according to plan with a delay of 3000 ms. But the initial launch is long.
How to speed it all up, split it into several, reducing the number of templates is not an option.

"use strict";

var gulp = require('gulp'),
  browserSync = require('browser-sync'),
  sass = require('gulp-sass'),
  uncss = require('gulp-uncss'),
  autoprefixer = require('gulp-autoprefixer'),
  sourcemaps = require('gulp-sourcemaps'),
  rename = require("gulp-rename"),
  plumber = require('gulp-plumber'),
  buffer = require('vinyl-buffer'),
  merge = require('merge-stream'),
  fs = require('fs'),
  cheerio = require('gulp-cheerio'),
  jadeInheritance = require('gulp-jade-inheritance'),
  jade = require('gulp-jade'),
  changed = require('gulp-changed'),
  cached = require('gulp-cached'),
  gulpif = require('gulp-if'),
  filter = require('gulp-filter');

var plugins = require("gulp-load-plugins")();

gulp.task('sass', function() {
  gulp.src('./sass/main.sass')
    .pipe(plumber())
    .pipe(plugins.sourcemaps.init())
    .pipe(sass({
        includePaths: ['./dist/css/'],
        onError: browserSync.notify
    }))
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: true
    }))
    // .pipe(uncss({
    //    html: ['*.html']
    // }))
    .pipe(plugins.sourcemaps.write("./"))
    .pipe(gulp.dest('./dist/css/'))
    .pipe(browserSync.reload({stream:true}));
});

gulp.task('skin-sass', function() {
  gulp.src('./sass/skin/*.sass')
    .pipe(plumber())
    .pipe(plugins.sourcemaps.init())
    .pipe(sass({
        includePaths: ['./dist/css/skin/'],
        onError: browserSync.notify
    }))
    .pipe(autoprefixer({
      browsers: ['last 2 versions'],
      cascade: true
    }))
    // .pipe(uncss({
    //    html: ['*.html']
    // }))
    .pipe(plugins.sourcemaps.write("./"))
    .pipe(gulp.dest('./dist/css/skin/'))
    .pipe(browserSync.reload({stream:true}));
});

// jade
gulp.task('jade', function() {
  gulp.src('./jade/**/*.jade')
    .pipe(changed('./dist/', {extension: '.html'}))
    .pipe(gulpif(global.isWatching, cached('jade')))
    .pipe(jadeInheritance({basedir: './jade/'}))
    .pipe(filter(function (file) {
      return !/\/_/.test(file.path) && !/^_/.test(file.relative);
    }))
    .pipe(plumber())
    .pipe(jade({
      pretty: '    '
    }))
    .pipe(gulp.dest('./dist/'))
    .pipe(browserSync.reload({stream:true}));
});

gulp.task('setWatch', function() {
  global.isWatching = true;
});

// Static server
gulp.task('browser-sync', function() {
  browserSync.init({
    server: {
      baseDir: "./"
    },
    notify: false,
    reloadDelay: 3000
  });
});

gulp.task('js', function(){
  gulp.src('./dist/**/*.js')
    .pipe(browserSync.reload({stream:true}))
});

gulp.task('watch', ['setWatch'], function () {
  gulp.watch('./sass/**/*.sass', ['sass']);
  gulp.watch('./sass/skin/*.sass', ['skin-sass']);
  gulp.watch('./jade/**/*.jade', ['jade']);
  gulp.watch('./dist/**/*.js', ['js']);
});

gulp.task('default', ['browser-sync','watch']);

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
lavezzi1, 2016-05-07
@lavezzi1

I use tars build. I now have about 200 templates (blocks) compiles in 25 seconds. Try https://github.com/tars/tars

D
Dark Hole, 2016-05-07
@abyrkov

Compression not rolling?

K
Konstantin Velichko, 2016-07-12
@Zoxon

https://github.com/juanfran/gulp-jade-inheritance

D
Dmitry Khristoev, 2016-07-12
@Haoss

it is above in my post, this is not a solution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question