0

What I want to do is add a custom script in package.json file that should run always before start and build scripts.

Things I want to do in my custom script:

  • Copy the favicon.ico file from /favicons/${process.env.REACT_APP_BRAND}.ico into /public, in order to overwrite the default one
  • Do a symlink from /src/assets/${process.env.REACT_APP_BRAND} to /src/assets/brand, in order to import images inside code without doing things like dynamic imports (which works but I think it's not their purpose)

I'm a bit lost with the structure of this custom script, and programming languange (its shell, but I'm on MacOS, so, it's better do it in node?)

Thank you.

sevenlops
  • 456
  • 1
  • 4
  • 18
  • 1
    Why don't you simply add a custom script in package.json and then reference it first thing in your `start` and `build` scripts? For example, `start: myOtherScript ...` – B Thuy Oct 27 '20 at 19:34
  • @BThuy yes but I'm newbie with npm (not with JS) and I don't know how to start, only I know that is possible. For example: this `myOtherScript`, where has to be placed? And with which language? I only want to do file changes, so Bash script can be done here? or it's better do it in JS in order to be platform agnostic (aka windows)? I just want a simple example, some entry point, BEST PRACTICES... – sevenlops Oct 27 '20 at 19:44
  • 1
    npm scripts run in your executing console and inherit its environment variables and such. So, you can add a script `myOtherScript: "echo 'myOtherScript'"` and use it like this: `start: "npm run myOtherScript && myStartScript"` – Iyashi Oct 27 '20 at 19:49
  • Just so you know: `npm start` is a predefined alias for `npm run start`. Every script defined in `package.json` can be called with `npm run [script-name]` – Iyashi Oct 27 '20 at 19:51

0 Answers0