-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
76 lines (68 loc) · 2.18 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const pug = require('gulp-pug');
const imagemin = require('gulp-imagemin');
const htmlValidator = require('gulp-w3c-html-validator');
const through2 = require('through2');
const htmlmin = require('gulp-htmlmin');
const browserSync = require('browser-sync').create();
//scss to css
function style() {
return gulp.src('assets/scss/**/*.scss', { sourcemaps: true })
.pipe(sass({
// outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(autoprefixer('last 2 versions'))
.pipe(gulp.dest('assets/css', { sourcemaps: '.' }));
}
// pug to html
function html() {
return gulp.src('assets/pug/pages/theme/chart-widget.pug')
.pipe(pug({ pretty: true }))
.on('error', console.error.bind(console))
.pipe(gulp.dest('theme'))
.pipe(browserSync.reload({stream: true}));
}
//Html validator
function validateHtml() {
function handleFile(file, encoding, callback) {
callback(null, file);
if (!file.w3cjs.success)
throw new Error('HTML validation error(s) found');
};
return gulp.src('pages/*.html')
.pipe(htmlValidator())
.pipe(through2.obj(handleFile));
}
// minify images
function image() {
return gulp.src('assets/virtual_images/*.*')
.pipe(imagemin())
.pipe(gulp.dest('assets/images'));
}
// minify html
function htmlminify() {
return gulp.src('html/index.html')
.pipe(htmlmin({ collapseWhitespace: true }))
.pipe(gulp.dest('html/minify'));
}
// Watch function
function watch(){
browserSync.init({
proxy: 'home/savan/Desktop/finalxologit/theme/index.html'
});
gulp.watch('assets/scss/**/*.scss', style);
gulp.watch('assets/pug/pages/theme/index.pug', html);
gulp.watch('./*.html').on('change', browserSync.reload);
gulp.watch('assets/css/*.css').on('change', browserSync.reload);
}
exports.style = style;
exports.html = html;
exports.watch = watch;
exports.image = image;
exports.validateHtml = validateHtml;
exports.htmlminify = htmlminify;
const build = gulp.series(watch);
gulp.task('default', build, 'browser-sync');