You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
muddletoes edited this page Jan 22, 2015
·
4 revisions
Node loader
If you'd like to skip using the sjs command 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:
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.
Alternatively, you can use sweet.loadMacro to achieve a similar effect to the --module command line flag:
varsweet=require('sweet.js');// load all exported macros in `macros/str.sjs`sweet.loadMacro('./macros/str');// test.sjs uses macros that have been defined and exported in `macros/str.sjs`require('./test.sjs');
This is basically equivalent to running sjs --module ./macros/str test.sjs.