* initialize @parcel/watcher watch & init browserSync * We are watching the files with extensions (.js, .ts, .html, .css, .scss) but we'll ignore folders like node_modules, dist & .git * Note: the watcher often send duplicate events, however the use of Set of file changes & the use of a setTim
()
| 35 | * Note: the watcher often send duplicate events, however the use of Set of file changes & the use of a setTimeout delay gets rid of this problem. |
| 36 | */ |
| 37 | async function init() { |
| 38 | subscription = subscribe(process.cwd(), (err, events) => { |
| 39 | if (err) return onError(err); |
| 40 | |
| 41 | for (const event of events) { |
| 42 | const absoluteFilePath = relative(process.cwd(), event.path); |
| 43 | onFileChanged(absoluteFilePath); |
| 44 | } |
| 45 | }, { |
| 46 | ignore: [ |
| 47 | '**/.git/**', |
| 48 | '**/dist/**', |
| 49 | '**/cypress/**', |
| 50 | '**/node_modules/**', |
| 51 | '!**/*.{ts,js,html,css,scss}' // which file extensions to watch |
| 52 | ] |
| 53 | }); |
| 54 | |
| 55 | // also watch for any Signal termination to cleanly exit the watch command |
| 56 | process.once('SIGINT', () => destroy()); |
| 57 | process.once('SIGTERM', () => destroy()); |
| 58 | process.stdin.on('end', () => destroy()); |
| 59 | process.stdin.on('exit', () => process.stdin.destroy()); |
| 60 | |
| 61 | // run full prod build `/dist` and full SASS build |
| 62 | if (!argv.serve) { |
| 63 | await executeFullBuild(); |
| 64 | buildAllSassFiles(); // start SASS build but no need to await it |
| 65 | } |
| 66 | |
| 67 | // start browser-sync server |
| 68 | startBrowserSync(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Initialize and start BrowserSync |
no test coverage detected