appy-one / acebase-server

A fast, low memory, transactional, index & query enabled NoSQL database server for node.js that easily syncs with browser and node.js clients and servers
MIT License
32 stars 14 forks source link

Fix Bundling Issues #56

Closed Azarattum closed 1 year ago

Azarattum commented 1 year ago

I use vite to bundle my project into a single file when building for production. acebase-server is currently not suitable for such builds.

After some investigation, I found out that swagger completely breaks in single-file builds. I thought it shouldn't be used in production mode. However, it's still gets bundled increasing file size by a factor for TWO! To solve this problem, I've changed docs imports to dynamic ones and simplified environment condition to be recognized by bundler. (I still needed to do replace({"process.env.NODE_ENV": '"production"'}) with @rollup/plugin-node-resolve though...)

The second problem was dynamically loaded package.json file which is obviously not present when acebase-server module is embedded into an application. To solve this we can use JSON imports from Typescript. This way during bundling the JSON data will be inlined properly. Btw, I did a little hack with @ts-ignore there because TypeScript got mad at the file not being at the source root (./src). It is still miles better that trying to load package.json from the filesystem, and crashing if it's not present.

Azarattum commented 1 year ago

@appy-one, everything is resolved here. Could you consider merging this?