Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel doesn't watch for file change #38

Open
ifndefdeadmau5 opened this issue Oct 29, 2018 · 7 comments
Open

Babel doesn't watch for file change #38

ifndefdeadmau5 opened this issue Oct 29, 2018 · 7 comments

Comments

@ifndefdeadmau5
Copy link

ifndefdeadmau5 commented Oct 29, 2018

For now I just restart manually after making changes because babel doesn't automatically transpile original code when changes are made.

So basically I feel getting no benefits from using nodemon from this setup.

Should I use another library for watching purpose?

@bryandbor
Copy link

bryandbor commented Nov 4, 2018

I agree with this. I can see that nodemon notices a change and restarts; however, it doesn't transpile the code and rerun the new code. That kind of defeats the purpose of nodemon watching for changes, doesn't it?

This was how I decided to setup my scripts. It restarts upon file changes and transpiles the code (using babel) correctly:

{
  "scripts": {
    "build": "babel -d lib src",
    "watch": "nodemon --watch src --exec yarn start",
    "start": "yarn build && yarn serve",
    "serve": "node lib/index",
    "test": "echo \"No test specified\" && exit 0"
  },
}

@ifndefdeadmau5
Copy link
Author

ifndefdeadmau5 commented Nov 5, 2018

@bryandbor Thank you for help! It works nicely. but it seems little bit slow because it builds whole code for every changes. Do you think any better solution exist?

@SeyTo
Copy link

SeyTo commented Nov 21, 2018

@ifndefdeadmau5 Maybe this could work.
"serve": "babel -w lib -d dist & nodemon dist --delay 800ms "
babel should just watch changes and convert to dist. Then nodemon picks up the new changes in the dist directory. The delay is be needed as nodemon will go crazy and restart everytime babel creates new files.

@SmolinPavel
Copy link

@bryandbor Thank you for help! It works nicely. but it seems little bit slow because it builds whole code for every changes. Do you think any better solution exist?

@ifndefdeadmau5 I think the solution you want is something like

"start": "nodemon --exec babel-node lib/index.js",

So what happens here - we just say nodemon to look for the initial file which is lib/index.js

@SaulSilver
Copy link

SaulSilver commented May 6, 2019

@SmolinPavel Thank you for the solution. Just to note that Babel do not recommend using babel-node for production as they state here: https://babeljs.io/docs/en/babel-node#not-meant-for-production-use

Not meant for production use
You should not be using babel-node in production. It is unnecessarily heavy, with high memory usage due to the cache being stored in memory. You will also always experience a startup performance penalty as the entire app needs to be compiled on the fly.

@SmolinPavel
Copy link

@SaulSilver Oh yeah, good shout! 👍 Thanks

@ser14joker
Copy link

You can set up your scripts like this:

"scripts": {
    "dev": "nodemon lib/index.js",
    "watch": "babel src --watch --out-dir lib"
  }

and run them in separate terminals; yarn watch or npm run watch will watch changes on src folder and yarn dev or npm run dev will run the compiled file with nodemon. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants