Skip to content

Minify your packages ahead of `npm publish` to reduce dependency bloat for your users.

License

Notifications You must be signed in to change notification settings

HughxDev/npm-minify

Repository files navigation

logo

npm-minify

Minify your packages ahead of npm publish to reduce dependency bloat for your users.

Downloads per month (NPM)

Installation

  • npm install --global npm-minify
  • yarn global add npm-minify

What it does

  1. Deletes and recreates a dist directory in the root of your project
  2. Recursively copies all the files you specify to dist
  3. Rewrites package.json to remove devDependencies and scripts, then minifies it
  4. Rewrites README, replacing a section marked # API with a link to your GitHub’s README

Npm-minify is non-destructive except for the dist directory.

What it doesn’t do

Minification of JavaScript or other assets. As package authors, we should assume that end users have their own build process and not publish pre-minified assets.

Usage

First, add a .npm-minify.js file to the root of your project, specifying which files should be copied (or not copied) to dist using a glob syntax. For example:

module.exports = {
  "filter": [
    "**/*.js",
    "rng/hvml.rng",
    "!**/*.test.js",
    "!jest.config.js",
    "!node_modules/**",
    "!coverage/**",
    "!dev.js",
    "!.npm-minify.js",
  ]
};

Then, when you’re ready to publish:

yarn version # or npm version
npm-minify
cd dist
npm publish

Alternatively, you can specify the filter list as a comma-separated command-line argument:

npm-minify --filter '**/*.js,rng/hvml.rng,!**/*.test.js,!jest.config.js,!node_modules/**,!coverage/**,!dev.js,!.npm-minify.js'

If you specify filter in both .npm-minify.js and as a command-line argument, npm-minify will combine the two.

If you specify no filter, then it defaults to copying over all .js files, while ignoring:

  • node_modules/
  • coverage/
  • test/
  • .test.js files
  • .npm-minify.js
  • jest.config.js
  • .eslintrc.js files and their variants

Flags

Flag Shorthand Description
--verbose -v Turn on verbose console logging
--filter -f Specify comma-separated list of files to include/exclude. Supports glob patterns.
--in -i Specify minification source directory.
--out -o Specify minifcation destination directory.

About

Minify your packages ahead of `npm publish` to reduce dependency bloat for your users.

Resources

License

Stars

Watchers

Forks

Packages

No packages published