Use custom build output folder when using create-react-app

后端 未结 13 895
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 17:24

Facebook provides a create-react-app command to build react apps. When we run npm run build, we see output in /build folder.

相关标签:
13条回答
  • 2020-12-04 18:10

    If you have arrived at this question three years after its initial posting because this is still a problem for you, consider backing this proposal to support a new BUILD_PATH environment variable.

    https://github.com/facebook/create-react-app/pull/8986

    From the proposal's documentation:

    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.

    If this proposal is adopted, it would mean that customizing the output target for create-react-app becomes as simple as updating updating your build script:

    // 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'
    
    0 讨论(0)
提交回复
热议问题