mem*_*eme 5 javascript es6-modules
我想编写一个 Javascript 库,并且希望用户仅在其 HTML 页面中导入该库的主文件。然而,我发现如果我使用类似的技巧
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)
}
Run Code Online (Sandbox Code Playgroud)
要包含的脚本的路径必须从 HTML 文件开始计算,这意味着用户必须将文件放在特定位置才能使其工作。
我想知道是否值得重写这些文件以包含为 ES6 模块。这样做会使脚本的路径相对于包含它的 Javascript 文件吗?如果没有,大型图书馆如何处理这个问题?
归档时间: |
|
查看次数: |
406 次 |
最近记录: |