-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.babel.js
133 lines (110 loc) · 3.79 KB
/
gulpfile.babel.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
130
131
132
133
import path from "path";
import gulp from "gulp";
import sass from "gulp-sass"
import autoprefixer from "gulp-autoprefixer"
import { spawn } from "child_process";
import BrowserSync from "browser-sync";
const browserSync = BrowserSync.create();
const hugoBin = path.resolve(process.cwd(), 'bin', 'hugo', 'hugo')
// Hugo arguments
const hugoArgsDefault = ["-d", "../dist", "-s", "site", "-v"];
const hugoArgsPreview = ["--buildDrafts", "--buildFuture", '-b', process.env.DEPLOY_PRIME_URL];
// Development tasks
gulp.task("hugo", (cb) => buildSite(cb));
gulp.task("hugo-preview", (cb) => buildSite(cb, hugoArgsPreview));
gulp.task('css', function (done) {
gulp.src([
'src/css/**/*.css',
'node_modules/bootstrap/dist/css/bootstrap.css',
'node_modules/owl.carousel/dist/assets/owl.carousel.css',
'node_modules/owl.carousel/dist/assets/owl.theme.default.css',
'node_modules/animate.css/animate.css',
'node_modules/@fortawesome/fontawesome-free-webfonts/css/fontawesome.css',
'node_modules/@fortawesome/fontawesome-free-webfonts/css/fa-regular.css',
'node_modules/@fortawesome/fontawesome-free-webfonts/css/fa-solid.css',
'node_modules/@fortawesome/fontawesome-free-webfonts/css/fa-brands.css',
'node_modules/netlify-cms/dist/cms.css'
])
.pipe(gulp.dest('dist/css'))
done()
})
// Compile SCSS files to CSS
gulp.task('scss', function (done) {
gulp.src('src/scss/**/*.scss')
.pipe(sass({
outputStyle: 'compressed'
}))
.pipe(autoprefixer({
browsers: ['last 20 versions']
}))
.pipe(gulp.dest('dist/css'))
done()
})
// Hash javascript
gulp.task('js', function (done) {
gulp.src([
'src/js/**/*',
'node_modules/jquery/dist/jquery.js',
'node_modules/popper.js/dist/umd/popper.js',
'node_modules/bootstrap/dist/js/bootstrap.js',
'node_modules/owl.carousel/dist/owl.carousel.js',
'node_modules/netlify-cms/dist/cms.js'
])
.pipe(gulp.dest('dist/js'))
done()
})
gulp.task('webfonts', function (done) {
gulp.src([
'node_modules/@fortawesome/fontawesome-free-webfonts/webfonts/**/*'
])
.pipe(gulp.dest('dist/webfonts'))
done()
})
gulp.task('img', function (done) {
gulp.src([
'src/img/**/*'
])
.pipe(gulp.dest('dist/img'))
done()
})
// Development server with browsersync
gulp.task("server", gulp.series(["hugo", "css", "scss", "js", "webfonts", "img"], () => {
browserSync.init({
server: {
baseDir: "./dist"
},
notify: false
});
gulp.watch('src/css/**/*', gulp.series(['css', 'hugo']))
gulp.watch('src/scss/**/*', gulp.series(['scss', 'hugo']))
gulp.watch('src/js/**/*', gulp.series(['js', 'hugo']))
gulp.watch('src/img/**/*', gulp.series(['img', 'hugo']))
gulp.watch("site/**/*", gulp.series(["hugo"]))
}));
// Watch asset folder for changes
gulp.task('watch', function () {
gulp.watch('src/css/**/*', gulp.series(['css']))
gulp.watch('src/scss/**/*', gulp.series(['scss']))
gulp.watch('src/js/**/*', gulp.series(['js']))
gulp.watch('src/img/**/*', gulp.series(['img']))
})
gulp.task('default', gulp.series(['css', 'scss', 'js', 'webfonts', 'img']))
/**
* Run hugo and build the site
*/
function buildSite(cb, options, environment = "development") {
const args = options ? hugoArgsDefault.concat(options) : hugoArgsDefault;
process.env.NODE_ENV = environment;
return spawn(hugoBin, args, { stdio: "inherit" }).on("close", (code) => {
if (code === 0) {
browserSync.reload();
cb();
} else {
browserSync.notify("Hugo build failed :(");
cb("Hugo build failed");
}
});
}
// Build/production tasks
gulp.task("build", gulp.series(["css", "scss", "js", "webfonts", "img"], (cb) => buildSite(cb, [], "production")));
gulp.task("build-preview", gulp.series(["css", "scss", "js", "webfonts", "img"], (cb) => buildSite(cb, hugoArgsPreview, "production")));