How to disable source maps for React JS Application

前端 未结 8 998
时光说笑
时光说笑 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:31

    For windows cmd and create-react-app + react-scripts,

    You should use set and close with \" YOUR_TMP_ENV_VAR \"

    See example:

    "deploy:prod:hosting": "set \"GENERATE_SOURCEMAP=false\" && npm run build
    

    this answer helped me: How to set environment variable in React JS..?

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

    You have to create a .env file in your root directory (same folder as package.json) and set GENERATE_SOURCEMAP=false on a single line.

    for additional configurations, you may refer to the documentation here: https://facebook.github.io/create-react-app/docs/advanced-configuration

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

    Solution for ejected create-react-app v2.1.3.

    Go to /config/webpack.config.js directory and change the following line:

    const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
    

    To:

    const shouldUseSourceMap = false;
    

    And Bob is your uncle.

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

    just remove &&

    "scripts": {    
        "start": "react-scripts start",
        "build": "GENERATE_SOURCEMAP=false react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      }
    
    0 讨论(0)
  • 2020-12-08 19:46

    After long struggle nothing worked. Finally what worked for me is changing sourcemap: false in webpack.config.prod.js inside nodemodules/react-script/config hopefully it will work for you too.

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

    What I have tested and which is working is to add this code in your .env.production file or .env file

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