-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
109 lines (97 loc) · 3.19 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
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var sassGlob = require('gulp-sass-glob');
var sourcemaps = require('gulp-sourcemaps');
var livereload = require('gulp-livereload');
var autoprefixer = require('gulp-autoprefixer');
var minifyCss = require('gulp-minify-css');
var handlebars = require('gulp-compile-handlebars');
var layouts = require('handlebars-layouts');
var browserSync = require('browser-sync');
handlebars.Handlebars.registerHelper(layouts(handlebars.Handlebars));
var jsPaths = [
"./bower_components/vue/dist/vue.js",
"./bower_components/vue-strap/dist/vue-strap.js",
"src/js/app.js",
];
var handlebarsConfig = {
index: {
templateData: {
aboutData: require('./static_data.json')
},
options: {
ignorePartials: true, //ignores the unknown footer2 partial in the handlebars template, defaults to false
batch : [
'./src/templates/',
'./src/templates/components/'
],
helpers : {
capitals : function(str){
return str.toUpperCase();
}
}
}
}
};
// Compile SCSS
gulp.task('sass', function () {
gulp.src('src/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sassGlob())
.pipe(sass())
.pipe(autoprefixer())
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build/css'))
});
// Compile JS
gulp.task('scripts', function() {
return gulp.src(jsPaths)
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build/js'));
});
// Compile layouts, pages, and partials into flat HTML files
gulp.task('handlebars', function() {
return gulp.src('src/templates/views/*.handlebars')
.pipe(handlebars(handlebarsConfig.index.templateData, handlebarsConfig.index.options))
.pipe(rename(function (path) {
// path.dirname += '/' + path.basename;
path.extname = '.html';
}))
.pipe(gulp.dest('./build'));
});
// Start a server with LiveReload to preview the site in
gulp.task('server', function(){
browserSync.init({
server: {
baseDir: "build"
}
});
});
// Watch for file changes
gulp.task('watch', function() {
gulp.watch('src/sass/**/*.scss', ['sass']);
gulp.watch('src/js/**/*.js', ['scripts']);
gulp.watch('src/templates/**/*.handlebars', ['handlebars']);
gulp.watch('src/templates/**/*.handlebars').on('change', browserSync.reload);
});
// Build the "build" folder by running all of the above tasks
gulp.task('build', ['sass', 'scripts', 'handlebars']);
// Run builds, run the server, and watch for file changes
gulp.task('default', ['build']);
gulp.task('serve', ['sass'], function(){
browserSync.init({
server: "./build"
});
gulp.watch('src/sass/**/*.scss', ['sass']);
gulp.watch('src/js/**/*.js', ['scripts']);
gulp.watch('src/templates/**/*.handlebars', ['handlebars']);
gulp.watch('src/templates/**/*.handlebars').on('change', browserSync.reload);
})