Closed arekzaluski closed 6 years ago
Hey,
It's difficult to import it in other libraries when format is set to
iife
.
Well, the rationale is that browsers like UMD, and module bundlers like ES modules (because they look at the module
property in package.json
). Before providing a UMD build, I'm curious about which build toolchain are you using. Perhaps you're overlooking something that would make the build work with the ES modules.
Is there a plan to add TypeScript support ?
No.
Feel free to send a PR with some typings, though. But don't expect much in terms of maintenance if the API changes (new method or whatever).
Thank you for quick answer. My library is written in Typescript and is using typescript-compiler. It has support for both Node.js and web. The problem I'm having is that web version is using intel-hex.browser.js
which does not export any module inside when format is set to iife
. That way I can't import or require it.
The problem I'm having is that web version is using
intel-hex.browser.js
Wait, what?
I'm reading through https://www.typescriptlang.org/docs/handbook/module-resolution.html , and I can't see any indication that typescript uses the browser
field in package.json
to fetch the module code. Are you pulling intel-hex.browser.js
manually somehow?
If you are writing import MemoryMap from 'nrf-intel-hex'
, then typescript should fetch the file pointed by the module
field of package.json
, and then let the typescript tools handle the output wrapper format (as per the -m
option in https://www.typescriptlang.org/docs/handbook/compiler-options.html ). Typescript should be able to understand and transpile ES6 module syntax, like https://github.com/NordicSemiconductor/nrf-intel-hex/blob/b67c4cd16055d60f0d4c8c3cbee768374204c717/intel-hex.js#L939
If typescript is somehow using the browser
field of the package.json
file of the nrf-intel-hex
module, then there's definitely something fishy (and undocumented) going on.
I should be more specific. I'm using browserify - http://browserify.org/ to build web dependencies.
Oh, so then the problem is that browserify does use the browser
field, and it fails to bundle a iife
module. Now that makes sense!!
(I still suggest you to look into making typescript output a browser bundle. I myself am a fan of RollupJS, which works wonderfully for this kind of bundling)
Thanks, I'll take a look into adding TypeScript support.
Hi @IvanSanchez . Great tool. I'm interested in using it but I have few questions that I hope you will be able to answer.
iife
. Isn't it better to change it toumd
?