PureDevOps Community

Custom build directory for reactjs npm run build

I have a reactjs application , i use to do npm run build and it creates the output in build/ directory and I want to build and keep in a custom directory , how can i do this ?

With react-scripts >= 4.0.2, this is officially supported:

By default, Create React App will output compiled assets to a /build directory adjacent to /src. You may use this variable to specify a new path for Create React App to output assets. BUILD_PATH should be specified as a path relative to the root of your project.

// package.json
  "scripts": {
    "build": "BUILD_PATH='./dist' react-scripts build",
    // ...
  },

or adding a .env file to the root of your project:

# .env
BUILD_PATH='./dist'