create react app not picking up .env files?

前端 未结 10 2083
醉话见心
醉话见心 2020-12-12 19:52

I am using create react app to bootstrap my app.

I have added two .env files .env.development and .env.production in the root.

10条回答
  •  温柔的废话
    2020-12-12 20:29

    If you want to use multiple environment like .env.development .env.production

    use dotenv-cli package

    add .env.development and .env.production in project root folder

    and your package.json

    "scripts": {
        "start": "react-app-rewired start",
        "build-dev": "dotenv -e .env.development react-app-rewired build",
        "build-prod": "dotenv -e .env.production react-app-rewired build",
        "build": "react-app-rewired build",
        "test": "react-app-rewired test --env=jsdom",
        "eject": "react-scripts eject"   
    },
    

    then build according to environment like

    npm run-script build-dev 
    

提交回复
热议问题