If you want to create a library, there are some steps you need to consider:
- Libraries can be found in
src/core/libs
- Files sould be in folders that (by convention) are named after the namespace they export to
- Files in subfolders of these will not be built unless they are named
index.js
- Files control their own namespaces, no exports are used (see below)
- The resulting filename will have the structure
folder_subfolder.min/max.js
. - If a file is in the
cables/
namespace, the resulting filename will befilename.js
- Every library in a subfolder (see 3.) needs an
index.js
as the main entry point. - Webpack builds minified and non-minified versions to
build/libs/
- use
npm run build
to build the libraries - libraries are coped to
../cables_api/public/libs_core/
Input structure:
libs
├── cgl
│ ├── cubemap
│ │ └── index.js
│ ├── light
│ │ ├── createShaders.js
│ │ └── index.js
│ └── functions.js
|── cables
└── vargetset.js
Output structure:
libs
├── cgl_cubemap.js
├── cgl_light.js
├── cgl_functions.js
├── vargetset.js
-
All libraries have to "provide" and own or use an existing namespace, i.e.:
libs/cables/math.js
:const add = (num1, num2) => num1 + num2; const sub = (num1, num2) => num1 - num2; CABLES.Math = { add: add, sub: sub }; // results in CABLES.Math.add(1, 2);
-
For the above example the exported file would be called
math.max/min.js
. -
This also means that these libraries may be dependent on other libraries being loaded alongside or before them (as above with
CABLES
). -
Handle with care!
-
You can use shared imports in subfolders like this:
libs/cables/math/index.js
:import linearAlgebra from "./linearAlgebra" // make sure libs/cables/math/linearAlgebra.js exists! const add = (num1, num2) => num1 + num2; const sub = (num1, num2) => num1 - num2; CABLES.Math = CABLES.MATH || {}; CABLES.Math.linearAlgebra = linearAlgebra; // results in // - file: // - CABLES.Math.linearAlgebra;
- Click the op in the UI
- Go to the
Core Libs
tab - Get your library file from the dropdown, click
Add
- Reload patch
- profit