-1

When I do: npm run build I would like to create a folder inside the build folder and move all build output inside that folder.

At this moment I'm doing this:

"prebuild": "npm run build:clean",
"build": "react-scripts build",
"postbuild": "mkdir dest && cp -r build/* dest && npm run build:clean && mv dest build",
"build:clean": "rimraf build/*",
  1. Clear build folder
  2. Build app
  3. Create dest folder
  4. Copy all that is inside in build folder in dest folder
  5. Clear build folder
  6. Move dest folder inside build folder

How can I reduce it?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Javier
  • 1,975
  • 3
  • 24
  • 46

1 Answers1

1

Simple answer is: you can't change it.

Build output is fixed in create-react-app and can't be changed, and this decision has its roots in philosophy of CRA.

Citing Dan Abramov, co-author of create-react-app:

I don’t think it is strange this feature is missing. Largely, it is intentional. It ensures most people have similar setups, and people can build tools (e.g. for deployment) assuming the same directory structure.

However, you can use trick backed-up by him, which is using mv to move build output:

"build": "react-scripts build && mv build {YOUR_PATH}"
Andrzej Ziółek
  • 2,241
  • 1
  • 13
  • 21