npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mangle-what

v0.0.1

Published

Find properties that are best mangling candidates.

Downloads

6

Readme

mangle-what

A small command-line utility to find properties that are good candidates for mangling or removal.

Mangling (compressing by shortening names) of properties can be tricky. Properties of built-ins, properties that may be referenced from external code and properties that are accessed using obj[var] and other dynamic constructs cannot be mangled. However, usually shortening just a couple of properties can give most of the possible size saving.

Usage

To see what may be worth mangling run the script on your optimized bundle:

mangle-what bundle.js

This will give you a table such as:

property            occurrences  overhead (bytes)  overhead (% total)
------------------  -----------  ----------------  ------------------
relativeTime        1572         17292             12.20
displayName         1629         16290             11.49
other               3145         12580             8.87
future              1572         7860              5.54
relative            1048         7336              5.17
parentLocale        506          5566              3.93
past                1572         4716              3.33
pluralRuleFunction  249          4233              2.99
locale              761          3805              2.68
one                 1135         2270              1.60

In this particular case (of a small React-ish app), mangling the first 9 properties reduced the minified (non-gzipped) bundle size from 833 kB to 752 kB, that is by about 10% of its overall size. Mangling and removing a couple more properties (in essence getting rid of unneeded pieces of locale data) brought that down to 546 kB, for a total saving of 34%.

Options

count

To print more or less properties:

mangle-what --count=5 bundle.js

ignore

To exclude some properties from the statistics:

mangle-what --ignore=past future other bundle.js

no-ignore-default

By default a number of built-in and DOM properties are ignored. A list maintained by Uglify is used for that. To allow all properties to be accounted for:

mangle-what --no-ignore-default bundle.js

Mangling properties

How to actually mangle the properties depends on the build setup, for instance with bare Uglify:

uglifyjs bundle.js \
            --mangle-props \
            --mangle-regex='/^(displayName|relativeTime)$/' \
            --output smaller-bundle.js

Or with Webpack:

plugins: [
    new webpack.optimize.UglifyJsPlugin({
        mangle: {props: {regex: /^(displayName|relativeTime)$/}}
    })
]

Removing properties

You may want to try babel-remove-props. In .babelrc:

{
    plugins: [
        ['transform-remove-props', /^(displayName|relativeTime)$/]
    ]
}

Unlike usual Babel transforms this one is best run on the bundled code, possibly using a second pass.
One full setup example can be found in this projects's webpack-config-js.

Installation

npm install --global mangle-what