there is a project that I need to introduce the viz.js file in order to implement a function.
so I put viz.js
in the static
directory, and then introduce it through the script tag in index.html
.
let head = document.getElementsByTagName("head")[0];
createElement("script", head, { src: "static/resource/plugin/viz.js" })
function createElement(tag, target, attrs){
let element = document.createElement(tag)
if(attrs && typeof attrs === "object"){
for(let key in attrs){
element.setAtrribute ? element.setAtrribute(key, attrs[key]) : element[key] = attrs[key]
}
}
target.append(element)
}
this method allows my project to run normally, but when I packaged the project into a framework and released it as a npm module package, I found in the test that because the static in the new project is an empty folder , it will lead to an error in this way, the introduced js does not exist, and the error unexpected token <
tries to solve the problem:
1 replaces the static folder in the module package for the new project, but I think this method is not reasonable. It is not convenient for
2 to modify the reference path of the script tag to the relative path createElement ("script", head, {src: ".. / static/resource/plugin/viz.js"})
but still recognized by the browser as static/resource/plugin/viz.js
. It is not advisable to
3 introduce viz, npm I viz.js
through npm and then introduce import" viz"
or import Viz from "viz"
in a js file somewhere. All reported errors, but no instructions were found for viz.js projects on GitHub. Abandon this method
4 introduce the local viz.js file by import or put viz.js in the src folder to report syntax error , indicating that there is a ts syntax, resulting in an error in the compilation process. Unable to start the project
5 to change the script tag path to https://cdn.bootcss.com/viz.j., which is feasible, but it is not safe to introduce online
framework: https://gitee.com/g2333/data_.