-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
98 lines (89 loc) · 3.08 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
var gulp = require('gulp');
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var mustache = require("gulp-mustache");
var uglify = require('gulp-uglify');
var handlebars = require('gulp-handlebars');
var concat = require('gulp-concat');
var wrap = require('gulp-wrap');
var declare = require('gulp-declare');
var usemin = require('gulp-usemin');
var ext_replace = require('gulp-ext-replace');
var minifyCss = require('gulp-minify-css');
var rimraf = require('gulp-rimraf');
function swallowError (error) {
// If you want details of the error in the console
console.log(error.toString());
this.emit('end');
}
gulp.task('sass', function () {
gulp.src('src/sass/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('dist/css'));
});
gulp.task('sass-prod', function () {
gulp.src('src/sass/**/*.scss')
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('dist/css'));
});
gulp.task('libmin', function(){
return gulp.src('src/partial-src/*.src')
.pipe(usemin({
assetsDir: '.',
css: [minifyCss(), 'concat'],
js: [uglify(), 'concat']
}))
.pipe(gulp.dest("dist/"));
});
gulp.task('fix-templates', ['libmin'], function(){
return gulp.src('dist/**/*.src')
.pipe(rimraf())
.pipe(ext_replace('.html', '.html.src'))
.pipe(gulp.dest("src/partial-compiled/"));
});
// Gulp Mustache Task
gulp.task('mustache', ['fix-templates'], function() {
gulp.src("src/*.html")
.pipe(mustache({},{},{}))
.pipe(gulp.dest("dist/"));
});
//Gulp handlebars
gulp.task('handlebars', function() {
gulp.src('src/templates/*.hbs')
.pipe(handlebars({
handlebars: require('handlebars')
}))
.pipe(wrap('Handlebars.template(<%= contents %>)'))
.pipe(declare({
namespace: 'App.templates',
noRedeclare: true, // Avoid duplicate declarations
}))
.pipe(concat('templates.js'))
.pipe(gulp.dest('dist/js/'));
});
gulp.task('compress', function() {
gulp.src('src/js/**/*.js')
.pipe(uglify())
.on('error', swallowError)
.pipe(gulp.dest('dist/js'));
});
gulp.task('copy', function () {
gulp.src('src/img/**/*').pipe(gulp.dest('dist/img'));
gulp.src('lib/font-awesome/fonts/*').pipe(gulp.dest('dist/fonts'));
});
gulp.task('build', ['sass','handlebars','compress','copy','mustache'] )
gulp.task('build-prod', ['sass-prod','handlebars','compress','copy','mustache'] )
gulp.task('default', ['build','watch']);
gulp.task('watch', function () {
gulp.watch('./src/sass/**/*.scss', ['sass']);
gulp.watch('./src/partial-src/*.src', ['libmin', 'fix-templates', 'mustache']);
gulp.watch('./src/*.html', ['mustache']);
gulp.watch('./src/partial/*.html', ['mustache']);
gulp.watch('./src/**/*.hbs', ['handlebars']);
gulp.watch('./src/js/**/*.js', ['compress']);
gulp.watch('./src/img/**/*', ['copy']);
gulp.watch('./lib/**/*', ['copy']);
gulp.watch('./libc/**/*', ['copy']);
});