While Syncing the metadata files between your local system and a target/Scratch org, you often want to exclude some of the source files. Similarly, you often have files to exclude when converting the source to the Salesforce DX project format. In both the above-said cases, you can exclude each individual file or you can also exclude all files in a specific directory with the help of the .forceignore file.
Use your IDE to create a .forceignore file to specify each file or the directories you want to exclude while syncing and converting.
The force:source:* commands excludes files that are specified in the .forceignore file while running. Names of some other files that the force:source:* commands automatically Ignore even if they aren’t included in your .forceignore file are given:
- Any source file or directory that begins with a “dot”, such as .prettierignore, .gitignore or .sfdx
- Any file that ends in .dup
- Package2-manifest.json etc.
If the metadata name has special characters (such as hyphen, forward slashes, or backward slash), we must encode the file name on the local file system. For e.g. if you push a custom app named Custom: Sales App, the colon must be encoded in the file name.
Custom%3A Sales App.app-meta.xml
If you need to reference a filename with special characters in the .forceignore file, you must use the encoded filename.
The .forceignore file functions similarly to the .gitignore. Here are some examples indicating how to exclude sources using .forceignore.
# Specify a relative path to a directory that you need to be ignored
# Specify the whole directory – any directory named “classes” is excluded
# Specify the file extensions – any file with the below extensions will be excluded
# Specify a specific file – any file that is specified will be ignored
Leave A Comment