# common-shakeify

> browserify tree shaking plugin using @indutny common-shake

Latest version **1.1.2** (published 2022-10-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install common-shakeify
pnpm add common-shakeify
yarn add common-shakeify
bun add common-shakeify
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.2 |
| Published | 2022-10-16 |
| First published | 2017-08-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 47.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 103 |
| Author | Renée Kooi |
| Maintainers | feross, gkatsev, zertosh, mafintosh, maxogden, thlorenz, terinjokes, jmm, mellowmelon, ashaffer88, balupton, cwmma, jprichardson, indutny, jryans, sethvincent, yoshuawuyts, ungoldman, ahdinosaur, elnounch, parshap, yerkopalma, forbeslindesay, leichtgewicht, garann, bret, anandthakker, mattdesl, hughsk, fpereira1, goto-bus-stop, bpostlethwaite, emilbayes, stevemao, pkrumins, tehshrike, defunctzombie, lukechilds, raynos |
| Keywords | browserify, common-shake, tree-shaking |

## Links

- npm: https://www.npmjs.com/package/common-shakeify
- Repository: https://github.com/browserify/common-shakeify
- Homepage: https://github.com/browserify/common-shakeify#readme
- Issues: https://github.com/browserify/common-shakeify/issues
- npm.io page: https://npm.io/package/common-shakeify

## Dependencies (5)

- [through2](https://npm.io/package/through2.md) ^2.0.3
- [wrap-comment](https://npm.io/package/wrap-comment.md) ^1.0.1
- [transform-ast](https://npm.io/package/transform-ast.md) ^2.4.3
- [convert-source-map](https://npm.io/package/convert-source-map.md) ^1.5.1
- [@goto-bus-stop/common-shake](https://npm.io/package/@goto-bus-stop/common-shake.md) ^2.3.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2022-10-16
- 1.1.1 — 2022-06-28
- 1.1.0 — 2022-06-28
- 1.0.0 — 2022-06-28
- 0.6.2 — 2019-06-30
- 0.6.1 — 2019-06-29
- 0.6.0 — 2019-02-26
- 0.5.4 — 2019-02-25
- 0.5.3 — 2019-01-15
- 0.5.2 — 2018-11-13
- 0.5.1 — 2018-08-21
- 0.5.0 — 2018-06-01
- 0.4.6 — 2018-03-16
- 0.4.5 — 2017-11-19
- 0.4.4 — 2017-10-21
- … 10 more at https://npm.io/package/common-shakeify/versions

## README

# common-shakeify

browserify tree shaking plugin based on [common-shake](https://github.com/goto-bus-stop/common-shake), the CommonJS tree shaker originally by [@indutny](https://github.com/indutny).

Comments out unused exports from CommonJS modules.

With input files:

```js
// math.js
exports.min = function (a, b) { return a < b ? a : b }
exports.max = function (a, b) { return a < b ? b : a }

// app.js
var math = require('./math')
console.log(math.max(10, 20))
```

This plugin will rewrite the files to:

```js
// math.js
/* common-shake removed: exports.min = */ void function (a, b) { return a < b ? a : b }
exports.max = function (a, b) { return a < b ? b : a }

// app.js
var math = require('./math')
console.log(math.max(10, 20))
```

Use a minifier on the output to remove the exports entirely.

## Install

```bash
npm install --save-dev common-shakeify
```

## Usage

With the browserify cli:

```bash
browserify -p common-shakeify /my/app.js > bundle.js
# Minify
uglify-js bundle.js --compress > bundle.min.js
```

With the browserify Node API:

```js
var commonShake = require('common-shakeify')

var b = browserify({ entries: '/my/app.js' })
  .plugin(commonShake, { /* options */ })
  .bundle()

// Minify & save
var uglify = require('minify-stream')
b
  .pipe(uglify())
  .pipe(fs.createWriteStream('bundle.min.js'))
```

Note that using a minifier transform like uglifyify doesn't eliminate the commented-out exports.
Transforms run _before_ common-shakeify, so you have to use a minifier on the final bundle to remove the unused exports.

## Options

### `verbose`, `v`

When true, print messages to stderr when exports are deleted, or the tree-shaker bails out on a module.
Default false.
The `verbose` flag only works when no custom handlers are passed, so if you're using eg. a custom `onExportDelete` you have to print these messages manually.

```bash
$ browserify -p [ common-shakeify -v ] app.js > bundle.js
common-shake: removed `decode` in node_modules/vlq/dist/vlq.js:10:7
common-shake: bailed out: `module.exports` assignment in node_modules/process-nextick-args/index.js:20:3
```

### `onExportDelete(filename, exportName)`

Handler called for every exported identifier that is being removed.
`filename` is the path to the file that exports the identifier. `exportName` is the name of the identifier. Return false to bail and keep the identifier.

### `onModuleBailout(module, reasons)`

Handler called when a module cannot be tree-shaked for some reason.
`module` is the [Module object from common-shake](https://github.com/indutny/common-shake/blob/master/lib/shake/module.js).
`reasons` is an array of reasons that caused this module to be deoptimised.

### `onGlobalBailout(reasons)`

Handler called when tree-shaking is skipped entirely, usually because there is a dynamic `require` call in the source.
`reasons` is an array of reasons for skipping tree-shaking.

### `ecmaVersion`

Parse with this ecmaVersion as interpreted by acorn. (default: 10)

## License

[MIT](./LICENSE)

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