|
|
|
# Node loader
|
|
|
|
|
|
|
|
If you'd like to skip using the `sjs` binary to compile your sweet.js code, you can use the node loader. This allows you to `require` sweet.js files that have the `.sjs` extension:
|
|
|
|
|
|
|
|
```js
|
|
|
|
var sjs = require('sweet.js'),
|
|
|
|
example = require('./example');
|
|
|
|
|
|
|
|
example.one;
|
|
|
|
```
|
|
|
|
|
|
|
|
Where ./example.sjs contains:
|
|
|
|
|
|
|
|
```js
|
|
|
|
// example.sjs
|
|
|
|
macro id {
|
|
|
|
rule { ($x) } => {
|
|
|
|
$x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.one = id (1);
|
|
|
|
```
|
|
|
|
|
|
|
|
Note that `require('sweet.js')` must come before any requires of `.sjs` code. Also note that this does not import any macros, it just uses sweet.js to compile files that contain macros before requiring them. If you're looking to modularize macros check out the [[modules]] wiki page. |
|
|
|
\ No newline at end of file |