-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgulpfile.js
110 lines (93 loc) · 2.36 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
"use strict";
// gulp
const gulp = require("gulp");
// needed for Jekyll command
const cp = require("child_process");
// load all of plugins in devDependencies from package.json
const plugin = require('gulp-load-plugins')({
pattern: ["*"],
overridePattern: true,
scope: ["devDependencies"],
rename: {
'postcss-easy-import': 'easyImport',
'postcss-preset-env': 'cssPresentEnv',
'css-declaration-sorter': 'cssDeclarationSorter'
}
});
const onError = (err) => {
console.log(err);
};
// BrowserSync
function browserSync(done) {
plugin.browserSync.init({
server: {
baseDir: "./_site/"
},
port: 3000
});
done();
}
// BrowserSync Reload
function browserSyncReload(done) {
plugin.browserSync.reload();
done();
}
// Clean assets
function clean() {
return plugin.del(["./_site/assets/"]);
}
// CSS task using PostCSS
function css() {
var postcssPlugins = [
// import CSS files using @import
plugin.easyImport(),
// PostCSS plugin converts modern CSS to polyfills
// based on browser support in .browserslistrc
plugin.cssPresentEnv(),
// re-order declartions based on property
plugin.cssDeclarationSorter({
order: 'concentric-css'
})
]
return gulp
.src("./assets/css/_inc/main.css")
.pipe(plugin.sourcemaps.init())
.pipe(plugin.postcss(postcssPlugins))
.pipe(plugin.sourcemaps.write('.'))
// We need to write the compiled CSS for local development
.pipe(gulp.dest("./_site/assets/css/"))
// This is the compiled file the remote theme will use
.pipe(gulp.dest("./assets/css/"))
.pipe(plugin.browserSync.stream());
}
// Jekyll
function jekyll() {
return cp.spawn("bundle", ["exec", "jekyll", "build"], {
stdio: "inherit"
});
}
// Watch files
function watchFiles() {
gulp.series(jekyll);
gulp.watch("./assets/css/_inc/*", css);
gulp.series(css, browserSyncReload)
gulp.watch(
[
"./_includes/**/*",
"./_layouts/**/*",
"./_pages/**/*",
"./_posts/**/*"
],
gulp.series(jekyll, css, browserSyncReload)
);
}
// define complex tasks
const build = gulp.series(clean, jekyll, css);
const watch = gulp.series(clean, jekyll, css, gulp.parallel(watchFiles, browserSync));
// export tasks
exports.css = css;
exports.jekyll = jekyll;
exports.clean = clean;
exports.build = build;
exports.watch = watch;
exports.default = build;