So far it feels like to solve a minor problem I am creating a far more complex problem and workflow.
It can feel like that at first, when youâre first jumping into it. But once you get over the initial learning curve, youâll find that youâre far more productive than before. You can do more in less time and end up with a more refined and efficient end product.
For frontend work, youâre going to need to import them, but to do that, youâre going to need to compile your scripts before shipping using Webpack or something similar. If you want to import your own files, and you should, then you will need to build them as an exportable module. The end product is a single compiled JS file, which is faster to download than many files if youâre not using HTTP2.
Check out the Webpack Getting Started Tutorial tutorial. Iâve found that a lot of people seem to struggle with webpack at first, but itâs really only as complicated as you make it out to be. Once you wrap your head around what itâs doing, itâs actually incredibly simple. But itâs very powerful and I think some people try to jump into that extra power too soon and confuse themselves.
You will need to reference your compiled output JS file in your HTML, instead of many different files. At the bottom of that tutorial is a description of âwatch modeâ, which is invaluable.
Once youâre comfortable with Webpack and your workflow allows for it, you can look into webpack-dev-server, which makes the whole pain of frontend development go away once you get it set up. But, I donât suggest that till youâre absolutely comfortable with basic webpack functionality. Same goes for Babel, if you end up running into that.
If you want to write your own modules, then you will probably need to change up the pattern of the way youâre currently writing your JS. Sitepoint has some good article on importing and exporting.
Like I said, there is a learning curve here. But I really suggest taking the dive into it. You will come out the other side a better, faster, and more productive developer.
Good luck. When you have more questions, Iâll do my best to help