oframe / ogl

Minimal WebGL Library
https://oframe.github.io/ogl/examples
3.77k stars 213 forks source link

Build for production #124

Closed zlac closed 2 years ago

zlac commented 2 years ago

How to make a build for production? I see all examples are using unminified files from src, I would like to have the library in one minified script. Ideally this one script would contain only modules that I use in my app.

Thanks

hansagames commented 2 years ago

Hi @zlac for that you need to use builder (webpack, rollup e.c) with trees shaking, as engine dont know what you use. Builder then will try to remove any non referenced code from final build. Other option is to reference minified version of ogl file from cdn e.c but it will contain whole core library as it dont know what you will use

Hope that helps

zlac commented 2 years ago

@hansagames thanks for the reply. I was hoping to find a package.json with build script to make a minified bundle of entire lib. Is there a production version of the lib on CDN?

I found only

'https://cdn.jsdelivr.net/npm/ogl'; 'https://unpkg.com/ogl'; 'https://cdn.skypack.dev/ogl';

but those are modules which load other files.

Is there a ogl.min.js on a CDN, a single script that contains entire library?

Or if anyone has. an example package.json with rollup or webpack?

Thanks

CodyJasonBennett commented 2 years ago

This library is production-ready, or at least for how you'd consume it; bundling & transpilation is generally kept to users as per their needs. As this library is vanilla/ESM-only, I think it'll be a hard ask for a minified ESM/UMD bundle.

As per your question, you'd use a bundler or build tool to do this (if you're just starting out or want something quick, tools like Vite are a great choice). For library authors, light transpilation & ESM/CJS targets are all you'd do.

gordonnl commented 2 years ago

Bundling everything (including extras) would likely include lots of unused code for your app, therefore unoptimised. Tree-shaking can only be done on a per-use basis.