Skip to content

Instantly share code, notes, and snippets.

@montasim
Last active July 16, 2024 09:06
Show Gist options
  • Save montasim/fabbd94a39ef802784c71e2843967f2d to your computer and use it in GitHub Desktop.
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
Author

montasim commented Jul 6, 2024

File Overview

The .yarnclean file is designed to help streamline projects by removing extraneous files from your node_modules directory, which can significantly reduce deployment sizes and improve deployment times. It's particularly useful in production environments where you want to minimize resource usage and speed up operations.

Descriptions of Common Entries

Test directories: These entries specify directories commonly used for tests, such as tests, test, tests, and powered-test. Since test files are not usually required in production, removing them can save space.

Asset directories: Directories like docs, doc, website, images, and assets are often not needed in production unless they are directly used by the application at runtime.

Examples: Directories named example or examples often contain sample code demonstrating how to use the library or module. These are typically not needed in production.

Code coverage directories: Directories such as coverage and .nyc_output which store code coverage data and are used for development and testing purposes.

Build scripts: Files like Makefile, Gulpfile.js, and Gruntfile.js are used for setting up or configuring build processes and are generally not required in production.

Configs: Various configuration files for continuous integration services and project configurations like appveyor.yml, circle.yml, codeship-services.yml, .gitattributes, and .editorconfig. These configurations are primarily for development use.

Miscellaneous files: Wildcard patterns like *.md to clean up all markdown files, which are often used for documentation.

Purpose and Benefits

Optimize storage: Reducing the footprint of node_modules can significantly decrease the amount of disk space used, especially in large projects with many dependencies.

Improve performance: Fewer files in node_modules can lead to faster installation times, quicker transfers across network in CI/CD pipelines, and reduced complexity in file handling during deployments.

Enhance security: By removing unnecessary files (especially build scripts and configurations), you reduce the surface area for potential security vulnerabilities.

Streamline deployments: Cleaner node_modules directories mean that packaging and deploying applications can be more efficient, with fewer files to process and manage.

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