forked from jadnco/static-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
141 lines (123 loc) · 3.6 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use strict';
const gulp = require('gulp');
const del = require('del');
const util = require('gulp-util');
const sass = require('gulp-sass');
const prefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');
const rename = require('gulp-rename');
const handlebars = require('gulp-compile-handlebars');
const browserSync = require('browser-sync');
const ghPages = require('gulp-gh-pages');
const sassGlob = require('gulp-sass-bulk-import');
const watch = require('gulp-watch');
const babel = require('gulp-babel');
var paths = {
src: { root: 'src' },
dist: { root: 'dist' },
init: function() {
this.src.sass = this.src.root + '/scss/main.scss';
this.src.templates = this.src.root + '/**/*.hbs';
this.src.javascript = [this.src.root + '/js/**/*.js', '!' + this.src.root + '/js/libs/*.js'];
this.src.libs = this.src.root + '/js/libs/*.js';
this.src.images = this.src.root + '/images/**/*.{jpg,jpeg,svg,png,gif}';
this.src.files = this.src.root + '/*.{html,txt}';
this.dist.css = this.dist.root + '/css';
this.dist.images = this.dist.root + '/images';
this.dist.javascript = this.dist.root + '/js';
this.dist.libs = this.dist.root + '/js/libs';
return this;
},
}.init();
gulp.task('serve', () => {
browserSync.init({
server: paths.dist.root,
open: false,
notify: false,
// Whether to listen on external
online: false,
});
});
gulp.task('styles', () => {
gulp.src([paths.src.sass])
.pipe(sassGlob())
.on('error', util.log)
.pipe(sass({
includePaths: ['src/scss'],
}))
.on('error', util.log)
.pipe(prefixer('last 2 versions'))
.on('error', util.log)
.pipe(gulp.dest(paths.dist.css))
.pipe(browserSync.reload({stream: true}));
});
/*
* Compile handlebars/partials into html
*/
gulp.task('templates', () => {
var opts = {
ignorePartials: true,
batch: ['src/partials'],
};
gulp.src([paths.src.root + '/*.hbs'])
.pipe(handlebars(null, opts))
.on('error', util.log)
.pipe(rename({
extname: '.html',
}))
.on('error', util.log)
.pipe(gulp.dest(paths.dist.root))
.pipe(browserSync.reload({stream: true}));
});
/*
* Bundle all javascript files
*/
gulp.task('scripts', () => {
gulp.src(paths.src.javascript)
.pipe(babel({
presets: ['es2015'],
}))
.pipe(concat('bundle.js'))
.on('error', util.log)
.pipe(uglify())
.on('error', util.log)
.pipe(gulp.dest(paths.dist.javascript))
.pipe(browserSync.reload({stream: true}));
/*
* Uglify JS libs and move to dist folder
*/
gulp.src([paths.src.libs])
.pipe(uglify())
.on('error', util.log)
.pipe(rename({
suffix: '.min',
}))
.on('error', util.log)
.pipe(gulp.dest(paths.dist.libs))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('images', () => {
gulp.src([paths.src.images])
.pipe(gulp.dest(paths.dist.images));
});
gulp.task('files', () => {
gulp.src([paths.src.files])
.pipe(gulp.dest(paths.dist.root));
});
watch(paths.src.images, () => {
gulp.start('images');
});
watch(paths.src.files, () => {
gulp.start('files');
});
gulp.task('watch', () => {
gulp.watch('src/scss/**/*.scss', ['styles']);
gulp.watch(paths.src.javascript, ['scripts']);
gulp.watch(paths.src.templates, ['templates']);
});
gulp.task('deploy', () => {
return gulp.src([paths.dist.root + '/**/*'])
.pipe(ghPages());
});
gulp.task('default', ['watch', 'serve', 'images', 'files', 'styles', 'scripts', 'templates']);