This is vague - I apologize in advance, I am trying to be as succinct as I can with my limited understanding, while exposing my potentially incorrect assumptions.
I have a website that's literally one huge HTML file. It runs scripts defined in-line in a <scripts>
tag.
My goal is to move all the scripts into individual .js
files and pull them into index.html
(or into one another where required). I am familiar with the usage of Node's require
and I am familiar with import, as used in Angular. I stress usage because I don't really know how they work.
Assumption 1: I cannot use require
- it is purely for Node.js. The reason I bring it up is that I am pretty sure I have seen require in AngularJS 1.5
code, so assuming makes me uncomfortable. I am guessing this was stitched together by WebPack, Gulp, or similar.
Assumption 2: I should use import
, but import only works with a URL address, if I have my .js
hosted on a server or CDN, it will be be pulled. BUT, I cannot give local pathing (on the server) here - index.html
will NOT automatically pull in the dependencies while being served. I need npm/Webpack/other
to pre-compile my index.html
if I want the deps pulled in on the server.
Assumption 3: Pre-compiling into a single, ready-to-go, html file is the desired way to build things, because the file can be served quickly (assuming it's ready to go). I make the assumption with the recent trend of serving Markdown from CDNs, the appearance of the JAMstack, and the number of sites using Jekyll and such (though admittedly for traditional Jekyll sites).
Assumption 4: I also want to go to Typescript eventually, but I assume that changes nothing, since I will just pull in TS to compile it down to .js
and then use whatever solution I used above
Question: If it's clear what I am trying to do and what confuses me, is a decent solution to look into npm/Webpack
to stich together my .js
files? What would prepare them for being stiched together, using import/export? If so, is there an example of how this is usually done?