4

I was wondering if there was a way to exclude a .js file from

npm run build

I have tried adding

"build": "react-scripts build && rm -rf build/config-local.js",

into package.json but it tells me:

rm is not recognized as a function

is there a simple solution to this issue

Thank you

5
  • 1
    rm is not recognized because you are probably using a Windows system. Try del. Commented Apr 12, 2018 at 15:59
  • 3
    Also, this is really an XY problem. Commented Apr 12, 2018 at 15:59
  • I am not at the liberty of selecting a system, I have to use windows for this specific app. Commented Apr 12, 2018 at 18:07
  • i am aware this is an XY problem ish I am trying to find the cleanest way to exclude a file from build. Commented Apr 12, 2018 at 18:08
  • I didn't say you had to switch the OS, just try the del command: && del build\\config-local.js -- Note the escaped backslash. Commented Apr 12, 2018 at 18:20

1 Answer 1

6

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.

  1. Firstly cd to your project directory and install rimraf by running the following command:

    npm install rimraf --save-dev
    
  2. 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

Sign up to request clarification or add additional context in comments.

1 Comment

I got a couple dependancy issues with rimraf but it worked, thank you very much for your help, you saved me a lot of research

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.