Minify your packages ahead of npm publish to reduce dependency bloat for your users.
npm install --global npm-minifyyarn global add npm-minify
- Deletes and recreates a
distdirectory in the root of your project - Recursively copies all the files you specify to
dist - Rewrites
package.jsonto removedevDependenciesandscripts, then minifies it - Rewrites
README, replacing a section marked# APIwith a link to your GitHub’sREADME
Npm-minify is non-destructive except for the dist directory.
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.
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 publishAlternatively, 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.jsfiles.npm-minify.jsjest.config.js.eslintrc.jsfiles and their variants
| 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. |