How to disable source maps for React JS Application

前端 未结 8 999
时光说笑
时光说笑 2020-12-08 19:15

My react folder structure is as below

I\'ve not used the create-react-app version. I tried using GENERATE_SOURCEMAP=false. But It didn\'t work.

相关标签:
8条回答
  • 2020-12-08 19:47

    This works for me. Hope it helps anyone.

    // package.json
    
    "build": "react-scripts build",
    "postbuild": "rimraf build/**/*.map"
    

    This way, it will auto delete map files during build generation.

    0 讨论(0)
  • 2020-12-08 19:49

    Solution 1

    Edit you package.json like below:

    • Windows:
        "scripts": {
            "start": "react-scripts start",
            "build": "set \"GENERATE_SOURCEMAP=false\" &&  react-scripts build",
            "test": "react-scripts test",
            "eject": "react-scripts eject"
          },
    
    • Linux:
        "scripts": {
            "start": "react-scripts start",
            "build": "GENERATE_SOURCEMAP=false react-scripts build",
            "test": "react-scripts test",
            "eject": "react-scripts eject"
          },
    

    Solution 2 (Recommended)

    This solution is not operating system dependent and works on both Linux and Windows. Just create a file called .env and add the following line to it:

    GENERATE_SOURCEMAP=false
    
    0 讨论(0)
提交回复
热议问题