How to use a npm package for development without building it every time?
Leave the package.json file entry point set to the dist/index.js
file.
Then set a new scripts
option in the package.json file to run tsc <filename> -w
. This will run the TypeScript Compile command with the watch flag. This will recompile when files change in the directory.
If you have a different flow that doesn't use tsc
directly or doesn't support a watch flag then see the link below that usesnodemon
.
https://stackoverflow.com/a/48255950/5779200
You can't avoid the build process so it's best to embrace it and understand the advantages of not changing the entry point between the deployment and the development.
- Simple flow, just press start, and your startup script should run it on its own
- Same output in Prod and local development means less things to break
- Auto rebuilding on changes allow for faster development of not having to re-execute commands