Skip to content

Instantly share code, notes, and snippets.

@montasim
Last active September 24, 2025 06:44
Show Gist options
  • Select an option

  • Save montasim/fabbd94a39ef802784c71e2843967f2d to your computer and use it in GitHub Desktop.

Select an option

Save montasim/fabbd94a39ef802784c71e2843967f2d to your computer and use it in GitHub Desktop.
Using the .yarnclean file effectively helps maintain a cleaner, more efficient codebase and can be a crucial part of optimizing JavaScript projects that use Yarn as a package manager.
####################################################
# Yarn Clean Configuration File
####################################################
# This file lists patterns of files and directories that are deemed unnecessary and can be safely deleted after installing packages via Yarn.
# The cleaning process reduces the size of node_modules by removing unneeded files such as tests, documentation, and various configuration files.
####################################################
# Test Directories
# Purpose: Identify test directories that are not needed in production environments.
# Use: Automatically remove common directory names used for tests.
####################################################
__tests__
test
tests
powered-test
####################################################
# Asset Directories
# Purpose: Remove typical documentation and asset directories not needed in production.
# Use: Clean up common directories that contain documentation and media files.
####################################################
docs
doc
website
images
assets
####################################################
# Examples
# Purpose: Remove example files and directories.
# Use: Examples are generally not required for production builds.
####################################################
example
examples
####################################################
# Code Coverage Directories
# Purpose: Remove directories related to code coverage reports.
# Use: These directories are used during development and are not necessary in production.
####################################################
coverage
.nyc_output
####################################################
# Build Scripts
# Purpose: Identify build-related scripts that are not necessary post-installation.
# Use: Removes standard build script files.
####################################################
Makefile
Gulpfile.js
Gruntfile.js
####################################################
# Configuration Files
# Purpose: Clean up various CI/CD and project configuration files that are not needed in production.
# Use: Includes a variety of configuration files used by different tools and services.
####################################################
appveyor.yml
circle.yml
codeship-services.yml
codeship-steps.yml
wercker.yml
.tern-project
.gitattributes
.editorconfig
.*ignore
.eslintrc
.jshintrc
.flowconfig
.documentup.json
.yarn-metadata.json
.travis.yml
####################################################
# Miscellaneous
# Purpose: Target miscellaneous and markdown files which are generally not required for the functioning of the application.
# Use: Cleanup markdown files and other non-essential file types.
####################################################
*.md
@montasim
Copy link
Copy Markdown
Author

I encountered a problem with the .yarnclean file.

This example file specifies folders with tests test tests

Which are considered potentially unnecessary, but /storybook/dist/test contains the necessary modules and declarations required for the package to function (without this folder, Storybook cannot be run).

So, I found that while .yarnclean can be effective in removing unnecessary files, it doesn't actually do anything, and the size of the removed files isn't large enough to provide any benefit. More importantly, .yarnclean poses a potential threat of preventing some packages from installing and running correctly, since there's no clear agreement among developers that certain files and/or folders required for the package to run shouldn't have certain names and should be removed using .yarnclean. Therefore, I propose removing this .yarnclean file from repositories.

You’re absolutely right that the .yarnclean approach is risky because it relies on broad patterns (test, docs, examples, etc.) without context. As you mentioned with Storybook, some packages legitimately require these directories, and cleaning them can break functionality.

I also agree that the benefits are minimal today. With modern package managers and deployment strategies, the disk savings from .yarnclean are negligible compared to the risk of removing something essential.

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