-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
80 lines (68 loc) · 2.17 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
var gulp = require('gulp');
var sass = require('gulp-dart-sass');
var cleanCSS = require('gulp-clean-css');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var concat = require('gulp-concat');
var connect = require('gulp-connect-php');
var md5 = require("gulp-md5-plus");
var browserSync = require('browser-sync').create();
const existsSync = require('fs').existsSync;
var src = {
css: ['assets/css/src/app.scss', 'assets/fonts/devsante/style.css'],
js: [
'node_modules/headroom.js/dist/headroom.min.js',
'node_modules/js-cookie/src/js.cookie.js',
'node_modules/masonry-layout/dist/masonry.pkgd.js',
'assets/js/src/**/*.js'
],
php: 'site/**/*.php',
};
var dist = {
css: 'assets/css',
js: 'assets/js'
}
var min = {
css: 'assets/css/app.css',
js: 'assets/js/app.js'
}
function connectSync() {
const config = {router: 'kirby/router.php'}
// php.ini used for xdebug configuration
if(existsSync('./php.ini')) config.ini = './php.ini'
connect.server(config, function (){
browserSync.init({
proxy: '127.0.0.1:8000'
});
});
gulp.watch(["assets/css/src/*.scss",'site/snippets/**/*.scss'], {ignoreInitial: false}, css);
gulp.watch('assets/js/src/**/*.js', {ignoreInitial: false}, js);
gulp.watch(src.php).on('change', browserSync.reload);
};
function css() {
return gulp.src(src.css)
.pipe(sass().on('error', sass.logError))
.pipe(concat('app.css'))
.pipe(cleanCSS())
.pipe(gulp.dest(dist.css))
.pipe(browserSync.stream());
};
function js() {
return gulp.src(src.js)
.pipe(gulpif('!**/*.min.js', uglify())) // only uglify() files that have not been minified yet.
.pipe(concat('app.js'))
.pipe(gulp.dest(dist.js))
.pipe(browserSync.stream());
};
gulp.task('cachebust-css', function(){
return gulp.src(min.css)
.pipe(md5(10,['site/snippets/*.php','site/config/config.php']))
.pipe(gulp.dest(dist.css))
});
gulp.task('cachebust-js', function(){
return gulp.src(min.js)
.pipe(md5(10,['site/snippets/*.php','site/config/config.php']))
.pipe(gulp.dest(dist.js))
});
exports.default = connectSync;
gulp.task("prod", gulp.series("cachebust-css", "cachebust-js"));