-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
119 lines (104 loc) · 3.24 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
// include gulp
var gulp = require('gulp');
// include plug-ins
var jshint = require('gulp-jshint');
var changed = require('gulp-changed');
var imagemin = require('gulp-imagemin');
var htmlmin = require('gulp-htmlmin');
var concat = require('gulp-concat');
var stripDebug = require('gulp-strip-debug');
var uglify = require('gulp-uglify');
var autoprefix = require('gulp-autoprefixer');
var minifyCSS = require('gulp-minify-css');
var less = require('gulp-less');
// JS hint task
gulp.task('jshint', function () {
gulp.src('./src/JS/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// minify new images
gulp.task('imagemin', function () {
var imgSrc = './src/Images/**/*',
imgDst = './build/Images';
gulp.src(imgSrc)
.pipe(changed(imgDst))
.pipe(imagemin())
.pipe(gulp.dest(imgDst));
});
// minify new or changed HTML pages
gulp.task('htmlpage', function () {
var htmlSrc = './src/*.html',
htmlDst = './build';
gulp.src(htmlSrc)
.pipe(changed(htmlDst))
.pipe(htmlmin({collapseWhitespace: true, removeComments:true}))
.pipe(gulp.dest(htmlDst));
});
// JS concat, strip debugging and minify
gulp.task('scripts', function () {
gulp.src(['./src/JS/lib.js', './src/JS/*.js'])
.pipe(concat('Script.js'))
.pipe(stripDebug())
.pipe(uglify())
.pipe(gulp.dest('./build/JS/'));
});
// CSS concat, auto-prefix and minify
gulp.task('styles', function () {
var mySrc = './src/CSS/*.less',
myDst = './build/CSS/';
gulp.src(mySrc)
.pipe(less())
.pipe(changed(myDst))
.pipe(concat('Styles.css'))
.pipe(autoprefix('last 2 versions'))
.pipe(minifyCSS())
.pipe(gulp.dest(myDst));
});
// Copy .htaccess
gulp.task('copyfiles', function () {
var mySrc = './src/.htaccess',
myDst = './build/';
gulp.src(mySrc)
.pipe(changed(myDst))
.pipe(gulp.dest(myDst));
});
// Copy fonts
gulp.task('copyfonts', function () {
var mySrc = './src/Fonts/*',
myDst = './build/Fonts/';
gulp.src(mySrc)
.pipe(changed(myDst))
.pipe(gulp.dest(myDst));
});
// default gulp task
gulp.task('default', ['copyfiles', 'copyfonts', 'imagemin', 'jshint', 'htmlpage', 'scripts', 'styles'], function () {
// watch for .htaccess changes
gulp.watch('./src/.htaccess', function () {
gulp.run('copyfiles');
});
// watch for fonts changes
gulp.watch('./src/Fonts/*', function () {
gulp.run('copyfonts');
});
// watch for HTML changes
gulp.watch('./src/*.html', function () {
gulp.run('htmlpage');
});
// watch for JS changes
gulp.watch('./src/JS/*.js', function () {
gulp.run('jshint', 'scripts');
});
// watch for CSS changes
gulp.watch('./src/CSS/*.css', function () {
gulp.run('styles');
});
});
// gulp task: RUN
gulp.task('0run', ['copyfiles', 'copyfonts', 'imagemin', 'jshint', 'htmlpage', 'scripts', 'styles'], function () {
gulp.run('copyfiles');
gulp.run('copyfonts');
gulp.run('htmlpage');
gulp.run('jshint', 'scripts');
gulp.run('styles');
});