-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
57 lines (50 loc) · 1.33 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
const {
src,
dest,
series,
watch,
} = require('gulp');
const sass = require('gulp-sass');
const ejs = require('gulp-ejs');
const rename = require('gulp-rename');
const del = require('del');
const sync = require('browser-sync').create();
const { exec } = require('child_process');
function clean() {
return del('dist');
}
function generateHTML() {
// convert ejs templates to html using streams
return src('src/views/main.ejs')
.pipe(ejs({ title: 'Pinball game made with p5.js and planck.js' }))
.pipe(rename({ basename: 'index', extname: '.html' }))
.pipe(dest('dist'))
.on('end', sync.reload);
}
function generateCSS() {
// convert sass to css using streams
return src('src/scss/style.scss')
.pipe(sass())
.pipe(dest('dist'))
.on('end', sync.reload);
}
function generateJS() {
// bundle main js file & its imports using child process
return exec('npx rollup -c')
.on('exit', sync.reload);
}
function watchFiles() {
sync.init({
server: {
baseDir: './dist/',
index: 'index.html',
},
});
watch('src/views/*.ejs', { ignoreInitial: true }, generateHTML);
watch('src/scss/*.scss', { ignoreInitial: true }, generateCSS);
watch('src/**/*.js', { ignoreInitial: true }, generateJS);
}
module.exports = {
watch: watchFiles,
build: series(generateHTML, generateCSS, generateJS),
};