fergiemcdowall / search-index

A persistent, network resilient, full text search library for the browser and Node.js
MIT License
1.38k stars 149 forks source link

Bundling a little better? #609

Closed eklem closed 11 months ago

eklem commented 1 year ago

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.

eklem commented 1 year 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.

fergiemcdowall commented 1 year ago

Sounds good. The more portable these formats are, the better 👍👏

eklem commented 1 year ago

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.

eklem commented 1 year ago

And it seems I can look at how the browsers are doing imports now. https://twitter.com/wesbos/status/1640722393688600578

eklem commented 1 year ago

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?

eklem commented 1 year ago

And nother question: Where do you define that you build with browser.js? Or is that just for browser-tests?

fergiemcdowall commented 1 year ago

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.

fergiemcdowall commented 1 year ago

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)

eklem commented 11 months ago

I looked a bit at this, but there is too many moving parts that I don't understand, sorry.