如何使用 webpack 导入静态 url [英] How to import static url using webpack
问题描述
如何使用 webpack 导入静态 url:
How can I import a static url using webpack:
index.js
导入http://google.com/myscript.js"
推荐答案
你真的不清楚你想要做什么,但总的来说你有几个选择.
It's really unclear what you're trying to do, but in general you have a few options.
预下载脚本或通过 NPM 安装.这可能是处理外部依赖项的首选方式.一旦它是本地的,您就可以像任何其他模块一样轻松地
import
或require
它.
Pre-download the script or install it via NPM. This probably is the preferred way to deal with external dependencies. Once it is local you can easily
import
orrequire
it like any other module.
如果绝对必须动态加载,您将需要一个 3rd 方模块,例如 https://www.npmjs.com/package/scriptjs 可以在运行时轻松下载第 3 方模块并阻止脚本其余部分的执行,直到它被解析.
If it absolutely must be loaded dynamically you will need a 3rd party module such as https://www.npmjs.com/package/scriptjs which can easily download 3rd party modules at runtime and block the execution of the rest of the script until it has been parsed.
使用 标记并将其包含在您的网页中.这仅适用于可以在其他所有内容之前加载的一般依赖项(可能用于 polyfill 或您在任何地方都依赖的库,如 jquery.)
Use a <script>
tag and include it on your page. This only works if it's a general dependency that can be loaded before everything else (maybe for a polyfill or a library you depend on everywhere like jquery.)
希望能帮到你!
这篇关于如何使用 webpack 导入静态 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!