-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
90 lines (74 loc) · 2.2 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
const gulp = require('gulp');
const rollup = require('rollup-stream');
const rollupNode = require('rollup-plugin-node-resolve');
const rollupBuiltins = require('rollup-plugin-node-builtins');
const rollupCommonjs = require('rollup-plugin-commonjs');
const setSource = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const browserSync = require('browser-sync');
let cache;
function buildJS() {
return rollup({
input: './src/main.mjs',
format: 'iife',
cache,
sourcemap: true,
globals: {
'howler': 'Howl',
},
plugins: [
rollupNode(),
rollupBuiltins(),
rollupCommonjs({
include: ['node_modules/victor/**']
}),
]
})
.on('bundle', bundle => cache = bundle)
.pipe(setSource('app.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist', {sourcemaps: './'}));
}
function buildHTML() {
return gulp.src("./src/index.html")
.pipe(gulp.dest("./dist/"));
}
function buildCSS() {
return gulp.src("./src/**/*.css")
.pipe(gulp.dest("./dist/"))
.pipe(browserSync.stream());
}
function copyAssets() {
return gulp.src("./src/assets/**/*")
.pipe(gulp.dest("./dist/assets/"));
}
function watch() {
gulp.watch("./src/**/*.mjs", gulp.series(buildJS, reload));
gulp.watch("./src/**/*.html", gulp.series(buildHTML, reload));
gulp.watch("./src/**/*.css", buildCSS);
gulp.watch("./src/assets/**/*", gulp.series(copyAssets, reload));
}
function serve() {
browserSync.init({
server: "./dist",
open: false,
ghostMode: false,
});
}
async function reload() {
return browserSync.reload();
}
const child_process = require('child_process');
function pushHTMLToWebserver(done) {
child_process.exec(`scp -r dist/* [email protected]:/srv/http/tom.shea.at/ld42/`, done);
}
gulp.task(buildJS);
gulp.task(buildHTML);
gulp.task(buildCSS);
gulp.task(copyAssets);
gulp.task("build", gulp.parallel(buildJS, buildHTML, buildCSS, copyAssets));
gulp.task(watch);
gulp.task(serve);
gulp.task("dev", gulp.series("build", gulp.parallel(serve, watch)));
gulp.task("deploy", pushHTMLToWebserver);
gulp.task("publish", gulp.series("build", "deploy"));