-
Notifications
You must be signed in to change notification settings - Fork 0
/
serve.js
39 lines (32 loc) · 1.12 KB
/
serve.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
import bSync from 'browser-sync';
import { relative } from 'node:path';
import { buildJavaScript, buildSlides, buildStyle, copyAssets } from './build.js';
const server = bSync.create();
const baseDir = './public';
const cssDir = `${baseDir}/css`;
server.init({
ghostMode: false,
server: { baseDir }
});
server.watch('src/**/*.html', {}, (event, file) => {
console.log(`src/**/*.html -> ${event}: ${file}`);
buildSlides();
server.reload();
});
server.watch('src/js/**/*.js', {}, (event, file) => {
console.log(`src/js/**/*.js -> ${event}: ${file}`);
if (!['add', 'change'].includes(event)) return;
buildJavaScript([file]);
server.reload();
});
server.watch('src/styles/**/*.scss', {}, (event, file) => {
console.log(`src/styles/**/*.scss -> ${event}: ${file}`);
const modified = buildStyle();
server.reload(modified.map(path => relative(cssDir, path)));
});
server.watch('static/**/*', {}, (event, file) => {
console.log(`static/**/* -> ${event}: ${file}`);
if (!['add', 'change'].includes(event)) return;
const modified = copyAssets([file]);
server.reload(modified.map(path => relative(baseDir, path)));
});