-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
126 lines (112 loc) · 3.42 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
// Load gulp
var gulp = require('gulp');
var del = require('del');
// Load plugins
var plumber = require('gulp-plumber'),
concat = require('gulp-concat'),
sass = require('gulp-sass'),
livereload = require('gulp-livereload'),
jshint = require('gulp-jshint'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer'),
imagemin = require('gulp-imagemin'),
pixrem = require('gulp-pixrem');
//Define paths
var paths = {
scripts: ['src/site_js/site/util.js', 'src/site_js/site/main.js', 'src/site_js/site/*.js'],
vendor_head_scripts: ['src/site_js/vendor/head/*.js'],
vendor_foot_scripts: ['src/site_js/vendor/foot/console.js','src/site_js/vendor/foot/*.js'],
sass: ['src/site_sass/**/*.scss'],
html: ['src/__site_html/*.html', 'src/templates/**/*.html'],
images: ['public/assets/site_images/**/*']
};
// JS Hint
gulp.task('lint', function() {
return gulp.src(paths.scripts)
.pipe(plumber())
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Concat the site javascript and livereload
gulp.task('scripts', function() {
return gulp.src(paths.scripts)
.pipe(plumber())
.pipe(concat('global.js'))
.pipe(gulp.dest('public/assets/site_js/'))
.pipe(livereload());
});
// Concat the vendor javascript and livereload
gulp.task('vendor_head_scripts', function() {
return gulp.src(paths.vendor_head_scripts)
.pipe(plumber())
.pipe(concat('vendor-head.js'))
.pipe(gulp.dest('public/assets/site_js/vendor/'))
.pipe(livereload());
});
gulp.task('vendor_foot_scripts', function() {
return gulp.src(paths.vendor_foot_scripts)
.pipe(plumber())
.pipe(concat('vendor-foot.js'))
.pipe(gulp.dest('public/assets/site_js/vendor/'))
.pipe(livereload());
});
// Clean css build folder (in case Sass errors)
gulp.task('clean-css', function() {
del([
'public/assets/site_css/**'
]);
});
// Clean js folder
gulp.task('clean-js', function() {
del([
'public/assets/site_js/**'
]);
});
// Compile the sass + autoprefix + pixrem + livereload
gulp.task('sass', function() {
return gulp.src(paths.sass)
.pipe(plumber())
.pipe(sass({ outputStyle: 'compressed' }))
.pipe(autoprefixer('last 2 versions'))
.pipe(pixrem({ atrules: true }))
.pipe(gulp.dest('public/assets/site_css/'))
.pipe(livereload());
});
// Listen to HTML to trigger livereload
gulp.task('html', function() {
return gulp.src(paths.html)
.pipe(plumber())
.pipe(livereload());
});
// Minify images
gulp.task('images', function() {
return gulp.src(paths.images)
.pipe(plumber())
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('public/assets/site_images/'))
.pipe(livereload());
});
// Set the watch task for sass, html, JS
gulp.task('watch', function() {
livereload.listen();
gulp.watch(paths.sass, ['clean-css', 'sass']); // Clean css folder incase of any sass files
gulp.watch(paths.html, ['html']);
gulp.watch(paths.scripts, ['lint', 'scripts']);
gulp.watch(paths.vendor_head_scripts, ['vendor_head_scripts']);
gulp.watch(paths.vendor_foot_scripts, ['vendor_foot_scripts']);
});
// Set the default task when you run gulp, first clean, then normal functions
gulp.task('default', function() {
gulp.start(
'sass',
'scripts',
'vendor_head_scripts',
'vendor_foot_scripts',
'lint',
'images',
'watch'
);
});
gulp.task('clear', function (done) {
return cache.clearAll(done);
});