docs: custom module bundling
This commit is contained in:
parent
0fadd791e9
commit
2b9632fd39
1 changed files with 36 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
# Custom module
|
||||
|
||||
## Writing a custom module
|
||||
|
||||
Using the `-c / --custom-module` command-line switch, users can load a javascript file to tune the way Open Stage Control behaves regarding osc.
|
||||
|
||||
```js
|
||||
|
|
@ -44,6 +46,8 @@ module.exports = {
|
|||
|
||||
```
|
||||
|
||||
## Available globals
|
||||
|
||||
The module is executed in a restricted context, only a few globals are available :
|
||||
|
||||
- `console`: `object`
|
||||
|
|
@ -86,3 +90,35 @@ sendOsc({
|
|||
]
|
||||
})
|
||||
```
|
||||
|
||||
## Managing big modules
|
||||
|
||||
Custom modules don't let you use node's `require` function at runtime, but you can manage your sources in multiple files and bundle them into a single file before loading it in Open Stage Control.
|
||||
|
||||
The common pattern for this is using the [browserify](http://browserify.org/) library:
|
||||
|
||||
1. define some variable in `number.js`
|
||||
|
||||
```javascript
|
||||
module.exports = 42
|
||||
```
|
||||
|
||||
2. retreive it in your main module file (`main.js`):
|
||||
|
||||
```javascript
|
||||
var num = require('./number.js')
|
||||
|
||||
module.exports = {
|
||||
init: function(){
|
||||
console.log(num) // 42
|
||||
},
|
||||
oscInFilter: function(data){
|
||||
// etc
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
3. bundle your sources into `custom-module.js`:
|
||||
|
||||
`browserify main.js -o custom-module.js --standalone module.exports`
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue