如何使用 webpack 导入静态 url [英] How to import static url using webpack

查看:39
本文介绍了如何使用 webpack 导入静态 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 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.

  1. 预下载脚本或通过 NPM 安装.这可能是处理外部依赖项的首选方式.一旦它是本地的,您就可以像任何其他模块一样轻松地importrequire 它.

  1. 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 or require 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.

使用

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆