forked from Errec/web-learning-kit-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
104 lines (92 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
99
100
101
102
103
104
var autoprefixer = require('gulp-autoprefixer');
var beeper = require('beeper');
var browserSync = require('browser-sync');
var cache = require('gulp-cache');
var cleanCSS = require('gulp-clean-css');
var concat = require('gulp-concat');
var del = require('del');
var gulp = require('gulp');
var imagemin = require('gulp-imagemin');
var pug = require('gulp-pug');
var notify = require('gulp-notify');
var plumber = require('gulp-plumber');
var rename = require("gulp-rename");
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var gutil = require('gulp-util');
// sudo npm install gulp-uglify browser-sync gulp-plumber gulp-autoprefixer gulp-sass gulp-jade gulp-imagemin del gulp-cache gulp-clean-css gulp-sourcemaps gulp-concat beeper gulp-util gulp-rename gulp-notify --save-dev
var fs = require('fs');
var onError = function(err) {
notify.onError({
title: "Gulp error in " + err.plugin,
message: err.toString()
})(err);
beeper(3);
this.emit('end');
gutil.log(gutil.colors.red(err));
};
gulp.task('styles', function(){
gulp.src('styles/*.scss')
.pipe(plumber({ errorHandler: onError }))
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'expanded'}))
.pipe(autoprefixer({
browsers: ['last 5 versions'],
cascade: false}))
.pipe(sourcemaps.write('.'))
.pipe(rename({ suffix: '.min'}))
.pipe(gulp.dest('build/css'));
});
gulp.task('templates', function(){
gulp.src('templates/*.pug')
.pipe(plumber({ errorHandler: onError }))
.pipe(pug())
.pipe(gulp.dest('build/'));
});
gulp.task('scripts', function(){
return gulp.src(['js/vendor/jquery/dist/jquery.min.js', 'js/vendor/bootstrap/dist/js/bootstrap.min.js', 'js/main.js'])
.pipe(plumber({ errorHandler: onError }))
.pipe(sourcemaps.init())
.pipe(concat('all.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(rename({ suffix: '.min'}))
.pipe(gulp.dest('build/js'));
});
gulp.task('images', function(){
gulp.src('img/**/*')
.pipe(cache(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true})))
.pipe(gulp.dest('build/img/'));
});
gulp.task('clean', function() {
console.log('Deleting .build/');
del(['build/']);
});
gulp.task('copy-glyphicon-font', function() {
if (!fs.existsSync('build/js/vendor/bootstrap/dist/fonts/')) {
console.log("Moving Glyphicon fonts to 'build'");
gulp.src("js/vendor/bootstrap/dist/fonts/**.*")
.pipe(gulp.dest('build/js/vendor/bootstrap/dist/fonts/'));
}
});
gulp.task('default',['copy-glyphicon-font'], function() {
gulp.start('styles', 'templates', 'scripts', 'images');
});
gulp.task('watch', function(){
gulp.watch('styles/**/*', ['styles']);
gulp.watch('templates/*.pug', ['templates']);
gulp.watch('js/*.js', ['scripts']);
gulp.watch('img/**/*', ['images']);
// init server
browserSync.init({
server: {
proxy: "local.build",
baseDir: "build/"
}
});
gulp.watch(['build/**'], browserSync.reload);
});