I always wondered how to correctly add client-side javascript to my express project. I use Typescript, and I would also like to use Typescript typing (e.g. for jQuery) when writing javascripts for clients.
My project structure is as follows:
- root
- distance
- CSI
- Assistants
- Models
- registration
- Profile
- Wwwroot
What I have done so far:
I created all the javascript client files in wwwroot/js (e.g. jquery.min.js, registration-form.js) and I uploaded them to the header of the corresponding pages.
Disadvantages:
- I had to write ES5 javascript that is compatible with browsers that we would like to support
- I cannot place javascript files where they logically belong (for example, I would rather put my
registration-form.js in src/registration/ instead of wwwroot) - No Typescript is possible :( No Typescript typing, not passed to ES5, etc.
In some tutorials, I saw that they simply run npm install --save jquery and import them into their client-oriented files. Therefore, I feel that I must be missing some pretty important things, but I could not find any textbooks about this.
My question is:
What is the βright path / best practiceβ for writing client-side javascript in Typescript / Express applications (which should also ellimize the mentioned flaws)?
source share