简体   繁体   English

Typescript 带有使用 es6 模块的外部库

[英]Typescript with an external library using es6 modules

I would like to use Typescript with libraries that are not modules and are not typescript such as PixiJS and SortableJS.我想将 Typescript 与不是模块且不是 typescript 的库(例如 PixiJS 和 SortableJS)一起使用。 What would be the best way to do this using es6 modules?使用 es6 模块执行此操作的最佳方法是什么? I would prefer not to use something like webpacker.我宁愿不使用 webpacker 之类的东西。

I would suggest doing something like我建议做类似的事情

import * as Pixie from 'pixie.js'

Then you could use it like然后你可以像这样使用它

// Not familiar with what the libraries do or what they are
Pixie.doSomething or const pixie = new Pixie() 

As i am not familiar with the libraries you mentioned obviously i may have not quoted the correct path but you get the idea.由于我不熟悉你提到的库,显然我可能没有引用正确的路径,但你明白了。 When i use loadsh in my ts projects without webpack but pure ts this works import * as _ from 'loadsh当我在没有 webpack 但纯 ts 的 ts 项目中使用 loadsh 时,这可以import * as _ from 'loadsh

Be aware tho.请注意。 If u are not using webpack or something similar when u conpile with tsc it will bundle any library u import into the .js file every time u import it that means your files will be of substuntial size!如果您在使用 tsc 编译时没有使用 webpack 或类似的东西,它会在您每次导入时将您导入的任何库捆绑到 .js 文件中,这意味着您的文件将非常大!

Webpack helps you create all those libraries into external single bundles where all your.js files will receive them from that single bundle thus minimzing your file size. Webpack 可帮助您将所有这些库创建到外部单个包中,所有 your.js 文件将从该单个包中接收它们,从而最小化文件大小。

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

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