GithubHelp home page GithubHelp logo

ralphtheninja / tinyify Goto Github PK

View Code? Open in Web Editor NEW

This project forked from browserify/tinyify

0.0 1.0 0.0 74 KB

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

License: Other

JavaScript 100.00%

tinyify's Introduction

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

  • unassertify - Remove assert() calls
  • envify - Replace environment variables—by default, replaces NODE_ENV with "production"
  • uglifyify - Remove dead code from modules
  • common-shakeify - Remove unused exports from modules
  • browser-pack-flat - Output a "flat" bundle, with all modules in a single scope
  • bundle-collapser - When using the --no-flat option, bundle-collapser replaces file paths in require() calls with short module IDs
  • minify-stream - Uglify the final bundle

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 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 envify uglifyify common-shakeify browser-pack-flat uglify-js
browserify entry.js \
  -g unassertify \
  -g envify \
  -g uglifyify \
  -p common-shakeify \
  -p browser-pack-flat/plugin \
| uglifyjs -cm \
> output.js

Or with the Node API:

browserify('entry.js')
    .transform('unassertify', { global: true })
    .transform('@goto-bus-stop/envify', { global: true })
    .transform('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

tinyify's People

Contributors

goto-bus-stop avatar casr avatar ferares avatar toddself avatar yoshuawuyts avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.