简体   繁体   English

如何使用 NPM 中不可用的外部库或 react/webpack 中的 bower?

[英]How to use external library not available in NPM or bower in react/webpack?

I see this library here:我在这里看到这个库:

http://sztanko.github.io/crosslet/ http://sztanko.github.io/crosslet/

There is no bower install, there is no npm install, but I want to use it in my webpack reactjs ES6 app.没有 bower 安装,也没有 npm 安装,但我想在我的 webpack reactjs ES6 应用程序中使用它。 How can I do this properly?我怎样才能正确地做到这一点? If not possible with ES6, JSX is fine too.如果 ES6 无法实现,JSX 也可以。

Include the library as an external in your webpack configuration as described in the Webpack documentation .Webpack 文档中所述,将库作为external文件包含在您的 webpack 配置

You can then refer to it as a normal import in your code, and when it's webpacked, it creates import shims that expect to find the global.然后,您可以在代码中将其称为正常导入,并且当它被 webpacked 时,它会创建希望找到全局的导入垫片。

In addition to what @BrandanMolloy said, you can also just include it as an asset (js/css) within your project and utilize the libraries.除了@BrandanMolloy 所说的之外,您还可以将其作为资产 (js/css) 包含在您的项目中并使用这些库。 If you explore the examples within http://sztanko.github.io/crosslet/ you'll see a bunch of uses, eg如果您探索http://sztanko.github.io/crosslet/ 中的示例,您会看到很多用途,例如

new crosslet.MapView($("#map"),config);

here https://github.com/sztanko/crosslet/blob/gh-pages/examples/happiness/index.html这里https://github.com/sztanko/crosslet/blob/gh-pages/examples/happiness/index.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM