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

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

    Windows Powershell Script

    //package.json
    "scripts": {
        "postbuildNamingScript": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command ./powerShellPostBuildScript.ps1",
    
    
    // powerShellPostBuildScript.ps1
    move build/static/js build/new-folder-name 
    (Get-Content build/index.html).replace('static/js', 'new-folder-name') | Set-Content 
    build/index.html
    "Finished Running BuildScript"
    

    Running npm run postbuildNamingScript in powershell will move the JS files to build/new-folder-name and point to the new location from index.html.

提交回复
热议问题