-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
73 lines (55 loc) · 1.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
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cssnano = require('cssnano');
const minifyCss = require('gulp-clean-css');
const concat = require('gulp-concat');
gulp.task('test', function () {
console.log('Gulp is geinstalleerd');
});
// JS minifier
//command voor minifien: gulp useref
const {
src,
dest,
watch
} = require('gulp');
const minifyJs = require('gulp-uglify');
const sourceMaps = require('gulp-sourcemaps');
const bundleJs = () => {
return src('public/js/*.js')
.pipe(sourceMaps.init())
.pipe(minifyJs())
.pipe(concat('bundle.js'))
.pipe(sourceMaps.write())
.pipe(dest('public/js/'))
}
const devWatch = () => {
watch('public/js/', bundleJs)
}
exports.bundleJs = bundleJs;
exports.devWatch = devWatch;
// CSS minifier
const bundleCSS = () => {
return src('./public/css/*.css')
.pipe(minifyCss())
.pipe(concat('bundle.css'))
.pipe(dest('./public/css'));
}
const watchCSS = () => {
watch('./public/css/*.css', bundleCSS);
};
exports.bundleCSS = bundleCSS;
exports.watchCSS = watchCSS;
gulp.task('useref', function () {
return gulp.src('public/views/*.html')
.pipe(useref())
//zorgt ervoor dat alleen js bestanden worden geminified
.pipe(gulpIf('*.js', uglify()))
.pipe(gulp.dest('public/js'))
//zorgt ervoor dat alleen css bestanden worden geminified
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('public/css'))
});