https://github.com/ymichael/eggroll
commonjs bundler that hoists all module into a single scope.
https://github.com/ymichael/eggroll
browser commonjs javascript packaging
Last synced: over 1 year ago
JSON representation
commonjs bundler that hoists all module into a single scope.
- Host: GitHub
- URL: https://github.com/ymichael/eggroll
- Owner: ymichael
- License: mit
- Created: 2017-02-28T04:45:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-28T05:03:59.000Z (over 9 years ago)
- Last Synced: 2025-01-11T04:41:18.834Z (over 1 year ago)
- Topics: browser, commonjs, javascript, packaging
- Language: JavaScript
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eggroll
Commonjs module bundler that hoists all modules into a single scope so they can
be concatenated safely without wrapping them in individual function scopes.
This allows the resulting package to be minified more efficiently and minimizes
the extra overhead at runtime from evaluating these modules. See:
https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/
## How this works
> We implement the ideas described in
> http://www.nonblocking.io/2011/12/experimental-support-for-common-js-and.html
> that have been implemented in Google's closure compiler.
1. All local variables are prefixed with a module specific prefix so they don't
collide with local variables in other modules when added to the same scope.
2. `module.exports` and `exports.*` are replaced with a module specific global
that other modules then reference directly.
3. `require` calls are replace with the respective module specific globals.
Running eggroll on the
[rollup-comparison](https://github.com/nolanlawson/rollup-comparison): with output:
https://gist.github.com/ymichael/91ef54ca7c756530635285cf8eb41d6e (318 bytes gzipped).
## Installation
```
npm install -g eggroll
```
## Quick Start
```sh
# Outputs a bundle using main.js as the entry point.
$ eggroll bundle --resolve main.js
# Outputs a bundle using public/main.js as the entry point.
$ eggroll bundle --resolve --root ./public ./public/main.js
# Outputs a bundle containing just the given files
$ eggroll bundle --root ./public ./public/foo.js ./public/bar.js
```
## Usage
```sh
Usage: eggroll [options]
Commands:
deps [options] Output the dependencies found for the given entry
point
bundle [options] Bundle the given files
Options:
-h, --help Show help [boolean]
```
```sh
$ eggroll bundle -h
bin/cli.js bundle [options]
Options:
-h, --help Show help [boolean]
--prefix custom prefix for module variables[string] [default: "$$module$$"]
--resolve whether to resolve dependencies [boolean] [default: false]
--root root to resolve module ids
[string] [default: "process.cwd()"]
```
```sh
$ eggroll deps [options]
Options:
-h, --help Show help [boolean]
--entry module id of bundle entry point [string] [required]
--root root to resolve module ids
[string] [default: "process.cwd()"]
```
## API Example
```js
var eggroll = require('eggroll');
// TODO
```
## Other links
- Original idea: http://www.nonblocking.io/2011/12/experimental-support-for-common-js-and.html
- Motivation: https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/
- Initial prototype: https://runkit.com/ymichael/58b1076665aeab00137caeb3
- https://en.wikipedia.org/wiki/Egg_roll