rucksack

Bundle js files by replacing the require calls in-place.

$ rucksack

Bundle js files by replacing the require calls in-place.

Note: The current version is not really production ready. It does work for my use-cases, but it should be improved by parsing the real tree. Check out the falafel branch. Contributions in this direction are really welcome! 💖

You can install the package globally and use it as command line tool:

$ npm i -g rucksack

Then, run rucksack --help and see what the CLI tool can do.

$ rucksack --help
Usage: rucksack [options]
 
Options:
  -p, --path <path>               Sets the input js file path.                     
  -g, --global <global-variable>  Global variable name (it will be created when the
                                  commonjs environment will not be available)      
  -o, --output <path>             Specify an output file where to write the bundle 
                                  code.                                            
  -h, --help                      Displays this help.                              
  -v, --version                   Displays version information.                    
 
Examples:
  rucksack -p input.js
  rucksack -p input.js -o bundle.js
  rucksack -p input.js -o bundle.js -g LibraryName
 
Documentation can be found at https://github.com/IonicaBizau/rucksack#readme

Here is an example how to use this package as library. To install it locally, as library, you can do that using npm:

$ npm i --save rucksack
const rucksack = require("rucksack");
 
// math.js: 
// const sum = require("./sum.js"); 
// const square = require("./square.js"); 
// 
// module.exports = { 
//     sum: sum 
//   , square: square 
// }; 
 
// sum.js: 
// module.exports = (a, b) => a + b; 
 
// square.js: 
// module.exports = x => x * x; 
 
console.log(rucksack(`${__dirname}/math.js`, "Math"));
// => 
// "use strict"; 
// (function() { 
//     var _rucksackModule = typeof module !== "undefined" ? module : {}; 
//     const sum = (a, b) => a + b; 
//     const square = x => x * x; 
// 
//     _rucksackModule.exports = { 
//         sum: sum, 
//         square: square 
//     }; 
//     if (typeof module !== "object") 
//         window.Math = _rucksackModule.exports 
// })(); 

For full API reference, see the DOCUMENTATION.md file.

Have an idea? Found a bug? See how to contribute.

If you are using this library in one of your projects, add it in this list. ✨

MIT © Ionică Bizău