I have the following in ./js/parcel/build-js.js
(it is more or less a simplification of exactly what the API docs example does, except that it takes an optional --watch
argument):
#!/usr/bin/env node
const Bundler = require('parcel-bundler');
const path = require('path');
const watch = process.argv.indexOf('--watch') > 0;
if (watch) console.log('Watching files...');
(async function bundleJs() {
const jsBundler = new Bundler(path.join(__dirname, '../src/common.js'), {
watch,
hmr: false,
});
jsBundler.on('bundled', () => {
console.log('bundled!');
});
const bundle = await jsBundler.bundle();
console.log('done');
})();
When I run node js/parcel/build-js.js --watch
, it detects the first change to src/common.js
and prints:
Watching files...
✨ Built in 585ms.
bundled!
done
This is as I'd expect. When I edit and save src/common.js
, it sees that and then the total output becomes (done
gets deleted):
Watching files...
✨ Built in 585ms.
bundled!
✨ Built in 86ms.
bundled!
But after that, no file changes are detected. I make changes and save but it just sits there, producing no more output or updating the build. Why only once?
Note: If I do strace node js/parcel/build-js.js --watch
, it seems to just sit on an unfinished epoll_wait(3,
, which I guess means it's waiting for something, but maybe watching the wrong file...
Edit: Versions!
- parcel-bundler: 1.12.3
- node: 10.15.1
- Ubuntu 18.04
Edit: using parcel watch
This appears to be a system-wide thing for me. I did yarn globals add parcel
(which also installed 1.12.3), and now watching any JS file with parcel watch path/to/file.js
does the same thing.