These examples aim to demonstrate how to address various issues using sigma.js, and to showcase its API.
Each example is a valid mini project usable as a standalone application. This allows opening an example in CodeSandbox.com using their GitHubBox.com feature:
- Open in GitHub the root directory of a given example
- Change the
github.com
bygithubbox.com
in the URL bar then validate
It will create a new working code sandbox where you can live edit the code to see better how it works.
Since each example declares "sigma": "latest"
in its dependencies, if you want to edit an example using local sigma source code, you need to bypass this declaration.
Our solution to this problem is that you can run an example from this directory:
- Open a terminal in this examples listing directory:
cd path/to/sigma/examples
- Run
npm start --example=my-example
, withmy-example
being the name of an example subdirectory - Open localhost:3000 in your browser
You should see the example live, using local sigma sources.
- Copy the full
template
directory (let's say asmy-example
) - Rename the
examples/my-example/package.json
value for"name"
- Rename the
examples/my-example/index.html
value forhtml > head > title
- Update
examples/my-example/index.ts
so that it does what you want - Don't forget to port the eventual dependencies you declared in
examples/my-example/package.json
to this directory'sexamples/package.json
(so that it can be started with local sigma code)
If you need public files, accessible from the example through a permalink, you need to put them in a my-example/public
subfolder.
The examples rely on kotatsu
because of its out-of-the-box compatibility with webpack
which is also used in this repository to build the sources (especially to handle shaders).
However, since it is not completely straightforward to serve static file in a CodeSandbox example which does not use a well-known tool such as create-react-app
we have to cheat a little by using the following sandbox.config.json
file to force CodeSandbox to consider our examples as using create-react-app
just so our public
files are correctly served:
{
"infiniteLoopProtection": true,
"hardReloadOnChange": false,
"view": "browser",
"template": "create-react-app"
}
Note that this is not required for examples that don't rely on static assets.