-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
130 lines (112 loc) · 2.61 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
127
128
129
var gulp = require('gulp'),
fs = require('fs'),
$ = require('gulp-load-plugins')(),
pngquant = require('imagemin-pngquant'),
eventStream = require('event-stream');
// Include Path for Scss
var includesPaths = [
'assets/scss'
];
// Source directory
var srcDir = {
scss: [
'assets/scss/**/*.scss'
],
js: [
'assets/js/**/*.js',
'!assets/js/**/_*.js'
],
jsHint: [
'assets/js/**/*.js'
],
jshintrc: [
'.jshintrc'
],
img: [
'assets/img/**/*'
]
};
// Destination directory
var destDir = {
scss: 'dist/css',
js: 'dist/js',
img: 'dist/img'
};
// Sass
gulp.task('sass', function () {
return gulp.src(srcDir.scss)
.pipe($.plumber({
errorHandler: $.notify.onError('<%= error.message %>')
}))
.pipe($.sassGlob())
.pipe($.sourcemaps.init())
.pipe($.sass({
errLogToConsole: true,
outputStyle : 'compressed',
sourceComments : 'normal',
sourcemap : true,
includePaths : includesPaths
}))
.pipe($.sourcemaps.write('./map'))
.pipe(gulp.dest(destDir.scss));
});
// Minify All
gulp.task('jsconcat', function () {
return gulp.src(srcDir.js)
.pipe($.plumber({
errorHandler: $.notify.onError('<%= error.message %>')
}))
.pipe($.sourcemaps.init({
loadMaps: true
}))
.pipe($.babel({
"presets": ["es2015"]
}))
.pipe($.uglify({
output:{
comments: /^!/
}
}))
.pipe($.sourcemaps.write('./map'))
.pipe(gulp.dest(destDir.js));
});
// JS Hint
gulp.task('jshint', function () {
return gulp.src(srcDir.jsHint)
.pipe($.plumber())
.pipe($.jshint({
lookup: srcDir.jshintrc
}))
.pipe($.jshint.reporter('jshint-stylish'));
});
// JS task
gulp.task('js', gulp.parallel('jshint', 'jsconcat'));
// Build Libraries.
gulp.task('copylib', function () {
// pass gulp tasks to event stream.
// return eventStream.merge(
// );
});
// Image min
gulp.task('imagemin', function () {
return gulp.src(srcDir.img)
.pipe($.imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use : [pngquant()]
}))
.pipe(gulp.dest(destDir.img));
});
// watch
gulp.task('watch', function () {
// Make SASS
gulp.watch(srcDir.scss, gulp.task( 'sass' ) );
// Uglify all
gulp.watch(srcDir.jsHint, gulp.task( 'js' ) );
// Minify Image
gulp.watch(srcDir.img, gulp.task( 'imagemin' ) );
});
// Build
gulp.task('build', gulp.parallel( 'js', 'sass', 'imagemin') );
// Default Tasks
gulp.task('default', gulp.parallel('watch'));