There may be an easier way but this is how I've done it.
- Merge all your objects to a single object (select all and Join)
- Create a 1024x1024 empty image. Let's call it Lightmap.
- Create a UV map with Smart UV Project (press U in edit mode)
- For all materials you wish to bake, add an unused Image Texture node and choose Lightmap from the menu:
- From the Render Properties tab, find the Bake button.
Make sure your model has enough vertices to represent the baked lighting by subdividing it a few times in edit mode:
- For export, add your new Lightmap texture as the Base Color for one material. Do it by clicking that yellow dot on the left of the RGB picker.
- Assign that material to all faces you are going to export. This makes them a single "GLTF primitive".
- Export a GLTF.
Format: glTF Separate (.gltf + .bin + textures). Disable Normals and Vertex Colors export.
Normals cause discontinuities and vertex colors are written by the baker so they are not welcome in the input mesh.
The GLTF exporter uses a per-material setting to decide if surfaces or one or two-sided. You usually want all to be one-sided so please enable backface culling for exported materials.
In Cycles materials under Viewport Info:
In Eevee materials under Settings:
To check if your triangles are pointing the right direction, enable viewport backface culling under the Viewport Shading menu: