For example:
I have two servers that provides frontend: foobar.com
and dev.foobar.com
And two servers that provides api: api.foobar.com
and api.dev.foobar.com
And I have variables for api
In .env.production
:
REACT_APP_API = https://api.foobar.com
In .env.development
:
REACT_APP_API = https://api.dev.foobar.com
I need something like this:
// in package.json
"build": "react-scripts build", // for production
"build-dev": "NODE_ENV=development react-scripts build", // for development
But I found in docs that I cannot override NODE_ENV manually.
So, how can I create build for my dev server?
Maybe something like this?
First:
$ npm install dotenv-cli --save-dev
package.json:
```json
{
...
"scripts": {
...
"build": "react-scripts build",
"build-dev": "dotenv -e .env.development react-scripts build",
...
}
...
}
Yes, it works, thank you!
Creating an optimized production build...
Only this message in console a little confuse me in this case :)
Well, it will be a production build. There is intentionally no way to run build
and then get a development build. Because people do this by mistake (or due to misunderstanding) too often, and then deploy dev builds to production.
There is an existing issue about supporting staging builds. Maybe we鈥檒l implement this at some point. It is tracked in https://github.com/facebookincubator/create-react-app/issues/790.
Most helpful comment
Maybe something like this?
First:
package.json:
```json
{
...
"scripts": {
...
"build": "react-scripts build",
"build-dev": "dotenv -e .env.development react-scripts build",
...
}
...
}