Closed Egge21M closed 6 months ago
I want to move to having all the imports be done as import * as nip49 from 'nostr-tools/nip49'
instead of bundling everything always. Not adding new libraries to the bundle is part of nudging people into doing that.
It's exposed by this magic trick here: https://github.com/nbd-wtf/nostr-tools/blob/63ccc8b4c8fe7a1eb5d57595fc67b65fe9f80cbb/package.json#L163-L167
I agree that JavaScript is hell.
For it to work you probably need a recent module bundler and if you're using TypeScript then you need this in your tsconfig.json
:
{
...,
"compilerOptions": {
...,
"module": "ESNext",
"moduleResolution": "bundler"
}
}
I want to move to having all the imports be done as
import * as nip49 from 'nostr-tools/nip49'
instead of bundling everything always. Not adding new libraries to the bundle is part of nudging people into doing that.
Oh got it! Thanks for pointing that out. Wouldn't modern bundlers tree shake anything that's not required anyways?
This is perfect however. Will close PR and issue.
Wouldn't modern bundlers tree shake anything that's not required anyways?
I can't explain why, but in my experience no.
My best guess is that they're unable to tree-shake when you're importing from a file that is itself importing (with *
) a bunch of other things (like index.ts) because they don't know what kind of side-effects could be happening in these imports.
So we must import directly from these subfiles and never do the *
in them.
closes https://github.com/nbd-wtf/nostr-tools/issues/372
NIP49 is included in bundle, but can not be imported as its not exported.