mousetrap icon indicating copy to clipboard operation
mousetrap copied to clipboard

Minify npm package size

Open tnir opened this issue 6 years ago • 4 comments

The mousetrap npm has 676 kB in a local. Files in the tests can be removed in the distribution packages.

$ du -hd1 node_modules/mousetrap
508.0K	node_modules/mousetrap/tests
92.0K	node_modules/mousetrap/plugins
676.0K	node_modules/mousetrap
$ npm list
`-- [email protected]

tnir avatar Apr 07 '18 14:04 tnir

It should be sufficient to add the following to package.json:

"files": [
  "mousetrap*.js"
]

Then, npm pack produces:

👻 npm pack
npm notice 
npm notice 📦  [email protected]
npm notice === Tarball Contents === 
npm notice 746B   package.json    
npm notice 10.6kB LICENSE         
npm notice 33.1kB mousetrap.js    
npm notice 4.9kB  mousetrap.min.js
npm notice 3.3kB  README.md       
npm notice === Tarball Details === 
npm notice name:          mousetrap                               
npm notice version:       1.6.2                                   
npm notice filename:      mousetrap-1.6.2.tgz                     
npm notice package size:  16.1 kB                                 
npm notice unpacked size: 52.5 kB                                 
npm notice shasum:        25b06946a364d4cb865d1e5c54004a35735efa8d
npm notice integrity:     sha512-8DaVxh+jEP/Jo[...]4d9SxsTO+6TzQ==
npm notice total files:   5                                       
npm notice 
mousetrap-1.6.2.tgz

kleinfreund avatar Jan 03 '19 15:01 kleinfreund

@kleinfreund Are you creating a PR with that?

tnir avatar Jan 04 '19 07:01 tnir

@tnir Yes, I plan to do that.

However, what I proposed above is not sufficient because it would exclude the plugins. The following allows the plugins directory, but excludes any tests directories within.

"files": [
  "plugins/**/*.js",
  "!plugins/**/tests",
  "mousetrap*.js"
]

kleinfreund avatar Jan 04 '19 09:01 kleinfreund

any updates on this change? In addition to the bloat, the current tests/ dir contains an outdated/vulnerable version of jQuery (which is probably fine for tests, but not great to include in an npm bundle, regardless of whether the code is accessible).

pachewise avatar Apr 28 '21 04:04 pachewise