如何在 Webpack 中使用 webrtc-adapter (adapter.js) shim? [英] How to use webrtc-adapter (adapter.js) shim in Webpack?

查看:52
本文介绍了如何在 Webpack 中使用 webrtc-adapter (adapter.js) shim?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Webpack 捆绑的 commonjs 浏览器应用程序 (typescript).它使用 webrtc,所以我想使用来自 npm 的 webrtc-adapter 包.它是 adapter.js 的包,它使得在 firefox 和铬更容易.

I have a commonjs browser application (typescript) that I use Webpack to bundle. It uses webrtc so I want to use the webrtc-adapter package from npm. It is the package for adapter.js which makes working with webrtc between firefox & chrome easier.

在我的模块中,我希望能够访问修改后的导航器项目.例如,我可以简单地调用:

Inside my modules I want to be able to access the modified navigator item. For example, so I can simply call:

navigator.mediaDevices.getUserMedia

如果我需要这个包,然后像这样在我的模块中的某处使用变量,我可以让它工作:

I can get it to work if I require the package and then use the variable somewhere in my module like so:

var webrtc = require("webrtc-adapter");
// somewhere in module
console.log(webrtc.browserDetails);

但是,我不需要通过 webrtc-adapter 访问 browserDetails 或任何暴露的项目,我只想使用 navigator 对象上的 shimmed 调用.我已经尝试使用 webpack.ProvidePlugin 和 externals,但两者仍然要求我在某处使用该对象.

However, I don't need to access browserDetails or any of the exposed items by webrtc-adapter, I just want to use the shimmed calls on the navigator object. I've tried using webpack.ProvidePlugin and externals but both still require that I use the object somewhere.

有没有一种方法可以将带垫片的导航器加载到每个模块中,而不必要求然后在我的模块中的某处使用该变量?我知道我可以在配置中使用 external ,然后通过单独的脚本标签加载它,但我更喜欢将 webpack 捆绑在一起.

Is there a way I can load the shimmed navigator into each module without having to require and then use the variable somewhere in my modules? I know I can use external in the config and then load it via a separate script tag but I'd prefer to have webpack bundle it all together.

推荐答案

你试过像这样要求它吗?

have you tried just requiring it like this?

require('webrtc-adapter');

这篇关于如何在 Webpack 中使用 webrtc-adapter (adapter.js) shim?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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