In your code, mark sections and dependencies with //SECTION comments:
E.g. In sample.js:
var a = 'leading code is always included';//SECTION foofunction hello(msg) {console.log('hello ' + msg);}//SECTION bar REQUIRE foohello('do bar things');//SECTION baz REQUIRE foohello('do baz things');//SECTIONvar b = 'trailing code is always included';
Then build section-specific scripts with sectionify.
Only the required sections are kept:
> sectionify sample.js foovar a = 'leading code is always included';function hello(msg) {console.log('hello ' + msg);}var b = 'trailing code is always included';
REQUIREed sections get included for you:
> sectionify sample.js narfvar a = 'leading code is always included';function hello(msg) {console.log('hello ' + msg);}hello('do bar things');hello('do baz things');hello('do narf things');var b = 'trailing code is always included';
Build with multiple sections:
> sectionify sample.js bar bazvar a = 'leading code is always included';function hello(msg) {console.log('hello ' + msg);}hello('do bar things');hello('do baz things');var b = 'trailing code is always included';
Prepend a header string to the output:
> sectionify --header='// AUTO-GENERATED - DO NOT EDIT\n' sample.js// AUTO-GENERATED - DO NOT EDITvar a = 'leading code is always included';var b = 'trailing code is always included';