DIY file watcher with Parcel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// make sure you have @parcel/core and @parcel/config-default | |
// installed as devDependencies | |
import {Parcel} from '@parcel/core'; | |
import {spawn, ChildProcessWithoutNullStreams} from 'child_process'; | |
let bundler = new Parcel({ | |
entries: 'src/index.ts', | |
defaultConfig: '@parcel/config-default', | |
defaultTargetOptions: { distDir: `${process.cwd()}/dist` }, | |
}); | |
async function main() { | |
let cp: ChildProcessWithoutNullStreams; | |
await bundler.watch(() => { | |
cp?.kill() | |
cp = spawn("node",[`${process.cwd()}/dist/index.js`]) | |
cp.stderr.on('data', (data) => { | |
console.log(`stderr: ${data}`); | |
}) | |
cp.stdout.on('data', (data) => { | |
console.log(`stdout: ${data}`); | |
}); | |
}); | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment