Skip to content

Creating a source bundle

Ioannis Charalampidis edited this page Jun 7, 2016 · 4 revisions

Requirements

None. Just the files you want to encode.

Guidelines

A source bundle is just a folder that contains your files and the entry point file bundle.json.

This file defines which resources should be embedded in the bundle, which loader to use in order to read them and under which name they are exposed.

The typical bundle.json file is the following:

{
  "name": "bundle_name",
  "exports": {

  }
}

On the exports section you define which resources this bundle exports. Since more than one resource of the same type might exist in the bundle, they are grouped under the same loader class:

   "exports": {

      "Loader.Class": {
         "name1": "specs",
         "name2": "specs",
         ...
      }

   }

You can find all the currently available loader classes in the bundle.json Loader Classes document. Usually, the "specs" is just the URL to the resource, relative to the bundle directory. For example:

   "exports": {

      "THREE.VRMLLoader": {
         "objects/sphere": "sphere.vrml",
         "objects/cone": "cone.vrml",
         "backgrounds/earth": "models/backgrounds/earth.vrml"
      }

   }

But it's also possible that a loader requires a bit more complicated specifications:

   "exports": {
      "THREE.MD2CharacterLoader": {
         "ratamahatta": {
            "baseUrl": "${BUNDLE}/ratamahatta/",
            "body": "ratamahatta.md2",
            "skins": [ "ratamahatta.png", "ctf_b.png", "ctf_r.png", "dead.png", "gearwhore.png" ],
            "weapons":  [  [ "weapon.md2", "weapon.png" ]
            ]
         }
      }

You can always use the ${BUNDLE} macro, that expands to the full path of the source bundle folder.

You can read the bundle.json Reference document if you want more information.