Closed eklem closed 11 months ago
I guess UMD is out of the question, since the build process has to split the result on either levelDB for node or indexedDB for the browser. But ESM for the browser is good. And named exports.
Sounds good. The more portable these formats are, the better 👍👏
I'll try to make CJS and ESM for NodeJS and ESM for the browser. Possibly also UMD for the browser. Even if it isn't anything unified about it, UMD has an easier way to be included in an HTML page. Also makes it easier for search-index to co-exist with other scripts.
And it seems I can look at how the browsers are doing imports now. https://twitter.com/wesbos/status/1640722393688600578
It seems the bundled version pulls in the whole package.json-file. Does it need that?
And shouldn't main
and browser
in package.json point to files in the dist-folder?
And nother question: Where do you define that you build with browser.js? Or is that just for browser-tests?
I think that main
and browser
are correct, and that the only file that should be in the dist folder is that stand-alone version that can be included in a script tag. That said, I am not really an expert on package bundling, so it could be that there is a better way to do this.
I also think that we should probably be using shipping without a dist
folder and instead make dist
magically appear on installation by adding npm prepare
to package.json
. The UMD version could then be made available directly from GitHub for anybody wanting to bypass bundlers (and/or use it directly from a <script>
tag)
I looked a bit at this, but there is too many moving parts that I don't understand, sorry.
I was thinking of trying to bundle CJS, ESM and UMD versions + minified of search-index. And also make sure they have named exports. I'm having some difficulties using the existing ESM-version in the browser because of default export.