Skip to content

Instantly share code, notes, and snippets.

@maxdevjs
Last active August 15, 2018 19:28
Show Gist options
  • Save maxdevjs/e87ef8cdffc582d4e49564f690dd5138 to your computer and use it in GitHub Desktop.
Save maxdevjs/e87ef8cdffc582d4e49564f690dd5138 to your computer and use it in GitHub Desktop.
Temporary workaround for babel --watch failing after first change

Temporary workaround for babel --watch failing after first change.

I did find the issue when starting The Complete React Web Developer Course course.

[suggestion] babel --watch consistently fails (happening only on Linux?)

How it works

Install node-watch

npm install node-watch

add an entry to npm script

"scripts": {"watch-it-until-babel-watch-fails": "node ./watch-it.js"},

run the script a

npm run watch-it-until-babel-watch-fails

run live-server as always (looks like it can not be included in the npm script).

Todo

  • find out if and how it is possible to avoid double reload
//https://www.npmjs.com/package/node-watch
const watch = require('node-watch');
const { exec } = require('child_process');
watch('src', { recursive: true }, function(evt, name) {
console.log('%s changed.', name);
//https://stackoverflow.com/questions/20643470/execute-a-command-line-binary-with-node-js
exec('node_modules/.bin/babel src/app.js --out-file=public/scripts/app.js --presets=env,react', (err, stdout, stderr) => {
if (err) {
// node couldn't execute the command
return;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment