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

后端 未结 13 933
被撕碎了的回忆
被撕碎了的回忆 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:02

    Based on the answers by Ben Carp and Wallace Sidhrée:

    This is what I use to copy my entire build folder to my wamp public folder.

    package.json

    {
      "name": "[your project name]",
      "homepage": "http://localhost/[your project name]/",
      "version": "0.0.1",
      [...]
      "scripts": {
        "build": "react-scripts build",
        "postbuild": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./post_build.ps1",
        [...]
      },
    }
    

    post_build.ps1

    Copy-Item "./build/*" -Destination "C:/wamp64/www/[your project name]" -Recurse -force
    

    The homepage line is only needed if you are deploying to a subfolder on your server (See This answer from another question).

提交回复
热议问题