# mcjs

> Merge CommonJS modules into a single file. Overhead-free.

Latest version **2.0.0** (published 2016-08-31) · unlicensed license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install mcjs
pnpm add mcjs
yarn add mcjs
bun add mcjs
```

Provides the command `mcjs`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-08-31 |
| First published | 2015-01-04 |
| Weekly downloads | 0 |
| License | unlicensed |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Deema Ywanov |
| Maintainers | dfcreative |
| Keywords | browserify, npm, bundle, build, require, module, package, browser-pack, module-deps, commonjs, cjs, cjsc, uncommon, uncommonjs, webpack, merge modules, merge, compile, small, powerbuild |

## Links

- npm: https://www.npmjs.com/package/mcjs
- Repository: https://github.com/dfcreative/mcjs
- Issues: https://github.com/dfcreative/mcjs/issues
- npm.io page: https://npm.io/package/mcjs

## Dependencies (6)

- [escope](https://npm.io/package/escope.md) ^3.6.0
- [espree](https://npm.io/package/espree.md) ^3.1.7
- [nomnom](https://npm.io/package/nomnom.md) *
- [detective](https://npm.io/package/detective.md) ^4.3.1
- [escodegen](https://npm.io/package/escodegen.md) ^1.8.1
- [replace-requires](https://npm.io/package/replace-requires.md) ^1.0.3

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2016-08-31
- 1.0.2 — 2015-01-04
- 1.0.1 — 2015-01-04
- 1.0.0 — 2015-01-04

## README

# MCJS [![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)


**M**erge **C**ommon **JS** modules into a single module.

_MCJS_ produces a single module with all inner requirements merged into a single scope with resolved name conflicts. That way it gains maximum compressability and minimal overhead. Smaller than [browserify](), [component](), [webpack](), [powerbuild](), [small](https://www.npmjs.com/package/small).

## Some stats

Compare minified gzip-sizes:

| Package | Browserify | [bundle-collapser](https://npmjs.org/package/bundle-collapser) | MCJS | Effect |
|---|---|---|---|---|---|
| [plotly.js](https://github.com/plotly/plotly.js) | 516kb | 508kb | 494kb | 4.5% |
| [color-space](https://github.com/dfcreative/color-space) | 5kb |  | 4.4kb | 12% |
| [mcjs](https://github.com/dfcreative/color-space) | 4.02kb |  | 2.71kb | 32.6% |
| [mod](https://github.com/dfcreative/mod) | 16.5kb |  | 13kb | 27% |


# Usage

#### Install

`$ npm install mcjs`

Use as a browserify plugin:

```sh
browserify index.js -p mcjs/plugin
```


#### Build

_dep.js_:

```js
var z = 123;
module.exports = z;
```

_index.js_:
```js
var a = require('./dep');
module.exports = a;
```

Run `mcjs`:

`$ mcjs index.js > bundle.js`
or
`$ cat index.js | mcjs > bundle.js`


Resulting _bundle.js_:

```js
var m_a, m_index;

var z = 123;
m_a = z;

var a = m_a;
module.exports = a;
```


# Motivation

Closure compiler can expand any objects, so if to merge modules into a single scope, which means to resolve global vars conflict and to replace all `module.exports` and `require` calls, then we get one-scoped bundle, which closure compiler compresses the way better than separated by scopes browserified/compiled bundle.

_Mcjs_ does the same task as a ClosureCompiler with `--process_commonjs_modules` flag, but avoids creating of `goog.provide`'s and makes variables more human-readable.


[![NPM](https://nodei.co/npm/mcjs.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/mcjs/)


## Reference

* [The cost of small modules](https://nolanlawson.com/2016/08/15/the-cost-of-small-modules/)

---
_Source: https://npm.io/package/mcjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
