Create-react-app: How can I create build for my dev server?

Created on 31 Jul 2017  路  3Comments  路  Source: facebook/create-react-app

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?

question

Most helpful comment

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",
...
}
...
}

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rovansteen picture rovansteen  路  192Comments

acskck picture acskck  路  213Comments

sgriffey picture sgriffey  路  113Comments

ericdfields picture ericdfields  路  78Comments

daviseford picture daviseford  路  108Comments