Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minify npm package size #417

Open
tnir opened this issue Apr 7, 2018 · 4 comments
Open

Minify npm package size #417

tnir opened this issue Apr 7, 2018 · 4 comments

Comments

@tnir
Copy link

tnir commented Apr 7, 2018

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
`-- mousetrap@1.6.1
@kleinfreund
Copy link
Contributor

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

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

Then, npm pack produces:

👻 npm pack
npm notice 
npm notice 📦  mousetrap@1.6.2
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

@tnir
Copy link
Author

tnir commented Jan 4, 2019

@kleinfreund Are you creating a PR with that?

@kleinfreund
Copy link
Contributor

kleinfreund commented Jan 4, 2019

@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"
]

@pachewise
Copy link

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 added a commit to pachewise/mousetrap that referenced this issue May 25, 2021
Removing test and config files in npm package. Left plugin files though I am wondering if we need these.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants