You cannot exclude a .js file which is installed via your react-scripts build command without modifying react-scripts source code. So, I think your attempted solution of subsequently deleting the file is the simplest approach.
Explanation:
So why is it not working?
rm is not recognized as a function
- The
rm command is for removing files/folders via bash.
- The equivalent command for Windows (E.g. via
cmd.exe) is DEL.
So my guess is you're getting this error because you're running it on Windows.
Solution:
For a cross platform solution to removing file/folders(s) you can utilize rimraf.
Firstly cd to your project directory and install rimraf by running the following command:
npm install rimraf --save-dev
Then change your build script to the following in your package.json:
"build": "react-scripts build && rimraf build/config-local.js",
Note: the original rm -rf part has been replaced with rimraf
rmis not recognized because you are probably using a Windows system. Trydel.delcommand:&& del build\\config-local.js-- Note the escaped backslash.