Skip to content

Instantly share code, notes, and snippets.

@themanifold
Last active October 1, 2022 02:47
Show Gist options
  • Save themanifold/2cd180c2ec4d49dd61f5da8e25481c42 to your computer and use it in GitHub Desktop.
Save themanifold/2cd180c2ec4d49dd61f5da8e25481c42 to your computer and use it in GitHub Desktop.
Pruning useless node_modules with bash userland tools (find etc)
#!/usr/bin/env bash
find node_modules \( -name '__tests__' -o \
-name 'test' -o \
-name 'tests' -o \
-name 'powered-test' -o \
-name 'docs' -o \
-name 'doc' -o \
-name '.idea' -o \
-name '.vscode' -o \
-name 'website' -o \
-name 'images' -o \
-name 'assets' -o \
-name 'example' -o \
-name 'examples' -o \
-name 'coverage'-o \
-name '.nyc_output' -o \
-name "*.md" -o \
-name "*.ts" -o \
-name "*.jst" -o \
-name "*.coffee" -o \
-name "*.tgz" \) -exec rm -rf {} \;
@ad-m
Copy link

ad-m commented Nov 20, 2017

@themanifold, please replace | xargs rm -rf into --delete.

@octaharon
Copy link

octaharon commented Nov 27, 2017

I'd modified this like that
find ... | grep -v "/dist" | xargs rm -rf
you shouldn't be removing anything inside dist folder, it will break some packages, most notably ones that generate HTML's and stuff. For me it was mochawesome-report-generator (which contains "assets" in its "dist" folder) and some shitty react datepicker module, I believe

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