I want to write a Javascript library, and I want the user to only import the library's main file in his HTML page. However, I saw that if I use tricks like
function dynamicallyLoadScript(url) {
var script = document.createElement("script"); // create a script DOM node
script.src = url; // set its src to the provided URL
document.head.appendChild(script); // add it to the end of the head section of the page (could change 'head' to 'body' to add it to the end of the body section instead)
}
(credits https://stackoverflow.com/a/950146/11108302)
the paths to the scripts to include have to be computed starting from the HTML file, which means the user has to put the file in a specific position in order for this to work.
I was wondering whether it could be worth it to rewrite the files to include as ES6 modules. Would doing this make the path to the script relative to the Javascript file including it? If not, how do large libraries handle this?