-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdev.js
More file actions
42 lines (35 loc) · 1.06 KB
/
dev.js
File metadata and controls
42 lines (35 loc) · 1.06 KB
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
import { spawn } from 'child_process';
import chokidar from 'chokidar';
import { removeFileOrDir, copyPublicFolder, generateImports, buildLayouts } from './utils.js';
import LAYOUT_NAMES from './src/layouts.js';
const main = async () => {
const filePath = 'src/temp_index.html';
await removeFileOrDir(filePath);
await copyPublicFolder('dist');
await generateImports();
buildLayouts(filePath);
const parcel = spawn('npx', [
'parcel',
'serve',
filePath,
'--dist-dir',
'dist',
'--host',
process.env.IP,
'--port',
process.env.PORT,
], { stdio: 'inherit' });
const pathsToWatch = LAYOUT_NAMES.map((name) => `src/${name}/${name}.html`);
const watcher = chokidar.watch(pathsToWatch, { ignoreInitial: true });
watcher.on('change', (file) => {
console.log(`[dev] Detected change in: ${file}`);
buildLayouts(filePath);
});
parcel.on('close', async (code) => {
console.log(`[dev] Parcel dev server exited with code: ${code}`);
await removeFileOrDir(filePath);
await removeFileOrDir('src/generated-imports.js');
watcher.close();
});
};
main();