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

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

alleroux picture alleroux  路  3Comments

alleroux picture alleroux  路  3Comments

ap13p picture ap13p  路  3Comments

onelson picture onelson  路  3Comments