简体   繁体   中英

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. What would be the best way to do this using es6 modules? I would prefer not to use something like 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

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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