Skip to content

Instantly share code, notes, and snippets.

@chroline
Last active December 5, 2021 22:04
Show Gist options
  • Save chroline/c84b14d76f2c6305ec388cb8bd5756ee to your computer and use it in GitHub Desktop.
Save chroline/c84b14d76f2c6305ec388cb8bd5756ee to your computer and use it in GitHub Desktop.
DIY file watcher with Parcel
// 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