Skip to content

Instantly share code, notes, and snippets.

Last active July 23, 2020 10:10
Show Gist options
  • Save rileytg/6f2a1a8d982cbcee8cdcab37bfe344bb to your computer and use it in GitHub Desktop.
Save rileytg/6f2a1a8d982cbcee8cdcab37bfe344bb to your computer and use it in GitHub Desktop.

Why do I need 106mb of JS for an empty rails app?

$ cd /tmp
$ rails -v 
$ rails new my-app 
Using -T -d postgresql from /Users/rileytg/.railsrc # use postgres, dont use tests (usually add rspec). this is a fairly common rails stack.
Bundle complete! 14 Gemfile dependencies, 65 gems now installed.
Installing all JavaScript dependencies [4.2.2]
         run  yarn add @rails/webpacker@4.2.2 from "."
✨  Done in 17.36s.
Installing dev server for live reloading
         run  yarn add --dev webpack-dev-server from "."
✨  Done in 8.24s.
Webpacker successfully installed πŸŽ‰ 🍰
$ cd my-app/
$ du -h -d 1
 60K	./app
 32K	./bin                               🧐
120K	./config                          🧐 
106M	./node_modules                  🧐🧐🧐🧐🧐🧐🧐🧐🧐🧐🧐🧐🧐
  0B	./storage                         🧐
 16K	./public                            🧐
  0B	./lib
4.0K	./db
  0B	./log
 72K	./.git
 27M	./tmp
  0B	./vendor
134M	.

Whats in node_modules/?

$ du -h -d 1 node_modules/ | gsort -hr |  wc -l

# top 10
$ du -h -d 1 node_modules/ | gsort -hr |  head -n 10
106M	node_modules/
7.4M	node_modules//@babel
6.8M	node_modules//core-js
5.9M	node_modules//node-sass
4.8M	node_modules//lodash
3.2M	node_modules//caniuse-lite
3.1M	node_modules//es-abstract
2.8M	node_modules//csso
2.6M	node_modules//webpack
1.9M	node_modules//node-gyp

# middle(ish) 10
Rileys-MBP:my-app rileytg$ du -h -d 1 node_modules/ | gsort -hr |  head -n 384 | tail -n 10
 32K	node_modules//randombytes
 32K	node_modules//prr
 32K	node_modules//postcss-safe-parser
 32K	node_modules//postcss-media-minmax
 32K	node_modules//postcss-flexbugs-fixes
 32K	node_modules//postcss-color-gray
 32K	node_modules//parse-asn1
 32K	node_modules//object-copy
 32K	node_modules//npmlog
 32K	node_modules//mississippi
 # 20-30
$ du -h -d 1 node_modules/ | gsort -hr |  head -n 30 | tail -n 10
964K	node_modules//@types
848K	node_modules//webpack-dev-server
844K	node_modules//async
840K	node_modules//snapdragon
836K	node_modules//pako
824K	node_modules//source-map
752K	node_modules//neo-async
708K	node_modules//bluebird
676K	node_modules//uri-js
652K	node_modules//postcss-calc
Copy link

Basically several compilers are bundled (node sass, webpack and Babel) so that you don't have to download them as a user and their version is stable for the app. You can use a tool like pnpm to only ever have one copy of them on your system but these aren't deps that negativity impact the app.

Copy link

txssseal commented Jul 1, 2020

The real issue is if you were to generate a rails api new app and it had the javascript haha

Copy link

Not everything in node_modules is .js files

Copy link

YES, this exzessive module junk is driving me crazy!

Why does one need to create a node module for every 30 lines of micro-functionality js?

One should write a checker and if there's more content in .dotfiles and other junky definition files the module creation (node-module upload) should be denied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment