Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

tinyify

browserify56.9kApache-2.04.0.0

a browserify plugin that runs various optimizations, so you don't have to install them all manually.

browserify, minify, optimize, tree-shaking, uglify

readme

tinyify

a browserify plugin that runs various optimizations, so you don't have to install them all manually.

npm travis standard

npm install --save-dev tinyify

browserify -p tinyify app.js

Included

browser-pack-flat and bundle-collapser are both not used if the --full-paths option is passed to Browserify. This way you can still get all of tinyify's other optimizations when building for disc.

Options

Options can be provided on the command line using subarg syntax, or in a separate options object using the browserify API.

env: {}

Supply custom environment variables for @browserify/envify.

b.plugin('tinyify', {
  env: {
    PUBLIC_PATH: 'https://mywebsite.surge.sh/'
  }
})

This option is only available in the API. On the CLI, you can define environment variables beforehand instead:

PUBLIC_PATH=https://mywebsite.surge.sh browserify app.js -p tinyify

--no-flat, flat: false

Disable browser-pack-flat. This enables bundle-collapser instead which will still shrink the output bundle a bit by replacing file paths with short module IDs.

browserify app.js -p [ tinyify --no-flat ]
b.plugin('tinyify', { flat: false })

More options?

If you need further customisation, I recommend installing the tools separately instead:

npm install --save-dev unassertify @browserify/envify @browserify/uglifyify common-shakeify browser-pack-flat terser
browserify entry.js \
  -g unassertify \
  -g @browserify/envify \
  -g @browserify/uglifyify \
  -p common-shakeify \
  -p browser-pack-flat/plugin \
| terser -cm \
> output.js

Or with the Node API:

browserify('entry.js')
    .transform('unassertify', { global: true })
    .transform('@browserify/envify', { global: true })
    .transform('@browserify/uglifyify', { global: true })
    .plugin('common-shakeify')
    .plugin('browser-pack-flat/plugin')
    .bundle()
    .pipe(require('minify-stream')({ sourceMap: false }))
    .pipe(fs.createWriteStream('./output.js'))

Alternatively you can fork this repo and publish it on npm under a scope with your modifications.

License

Apache-2.0

changelog

tinyify change log

All notable changes to this project will be documented in this file.

This project adheres to Semantic Versioning.

4.0.0

  • Remove unused dependencies.
  • Update unassertify to 2.x.
  • Use @browserify/envify. It's the same as @goto-bus-stop/envify, just renamed.
  • Use @browserify/uglifyify, with support for more modern ES features.

3.1.0

  • Update common-shakeify to 1.1.1, which adds the ability to set ecmaVersion (and sets default to 10) and removes side-effect-free modules that declare sideEffects: false in package.json from parse tree.

3.0.0

  • breaking Update terser. Tinyify now requires Node.js 6.
  • Use patched envify from npm as @goto-bus-stop/envify.

2.5.2

  • Use a patched version of envify with support for newer syntax features.

2.5.1

  • Update common-shakeify to 0.6.0, this should have no observable effects.

2.5.0

  • Update common-shakeify to 0.5.2+, which fixes a syntax error issue, and which can remove exported functions that are only used inside other unused exported functions.

2.4.3

  • Remove direct dependency on uglify-es, use terser 3.7.6+.

2.4.2

2.4.1

  • Update uglifyify to v5. This aligns the uglifyify --debug flag handling with tinyify's. Chances of anything being broken before this patch are very small though.

2.4.0

  • Add bundle-collapser when --no-flat is passed, to still save some bytes even if browser-pack-flat is not used.
  • Automatically disable bundle-collapser and browser-pack-flat when the --full-paths option is passed to Browserify

2.3.0

  • add API to easily apply tinyify to other browserify pipelines, like generated by factor-bundle or split-require.

2.2.0

  • add a --no-flat option for use with other tools that expect browser-pack output, such as disc

2.1.1

2.1.0

  • Add env option for custom environment variables. (@yoshuawuyts in #2)

2.0.0

Update browser-pack-flat to v3.0.0. This fixes tinyify-ing entry points that assign exports, like what's common in choo apps:

// app.js
if (window) app.mount()
else module.exports = app

The breaking change is that browser-pack-flat bundles will no longer assign module.exports when not using --standalone. This should not be a problem in 99.999% of cases, and is the same as what browser-pack does.