-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
97 lines (88 loc) · 2.35 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const postcss = require('gulp-postcss');
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const cp = require('child_process');
const flatten = require('gulp-flatten');
const jekyll = process.platform === 'win32' ? 'jekyll.bat' : 'jekyll';
const source = require('vinyl-source-stream');
//const concatjs = require('gulp-concat');
const browserSync = require('browser-sync').create();
const pug = require('gulp-pug');
const paths = {
styles: {
src: 'assets/css/main.scss',
dest: '_site/assets/css',
destsecond: 'assets/css'
},
scripts: {
src: 'assets/js/main.js',
dest: '_site/assets/js',
destsecond: 'assets/js'
},
htmls: {
src: '_pugfiles/**/*.pug',
dest: '_includes/'
}
};
function jekyllBuild() {
return cp.spawn("bundle", ["exec", "jekyll", "build"], { stdio: "inherit" });
}
function style() {
return gulp.src(paths.styles.src)
.pipe(sass({
includePaths: ['css'],
outputStyle: 'expanded',
onError: browserSync.notify
}))
.pipe(postcss([
autoprefixer()
]))
.pipe(gulp.dest(paths.styles.dest))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest(paths.styles.destsecond));
}
function js() {
return gulp.src(paths.scripts.src)
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(paths.scripts.dest))
.pipe(browserSync.reload({stream:true}))
.pipe(gulp.dest(paths.scripts.destsecond));
}
function html() {
return gulp.src(paths.htmls.src)
.pipe(pug())
.pipe(gulp.dest(paths.htmls.dest))
.pipe(browserSync.reload({stream:true}))
}
function browserSyncServe(done) {
browserSync.init({
server: {
baseDir: "_site"
},
notify: false
})
done();
}
function browserSyncReload(done) {
browserSync.reload();
done();
}
function watch() {
gulp.watch(['assets/css/**/*.scss','assets/css/**/*.sass'], style)
gulp.watch(['assets/js/**/*.js', '!assets/js/**/*.min.js'], js)
gulp.watch(paths.htmls.src, html)
gulp.watch(
[
'*.html',
'_layouts/*.html',
'_includes/*'
],
gulp.series(jekyllBuild, browserSyncReload));
}
gulp.task('default', gulp.parallel(jekyllBuild, browserSyncServe, watch))