A
A
Arthur2019-11-22 16:35:53
React
Arthur, 2019-11-22 16:35:53

Correct setting of environment variables when building SPA?

Is it necessary to specify environment variables in a script command?
for example
package.json:
"build" : "API_URL=api/ node app.js"
And in the build:
npm run build
or can you specify when building a teamcity like this?
package.json:
"build" : "node app.js"
And in assembly:

ENV API_URL=api/
npm run build

Will the variables be available? Now for some reason they are undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arthur, 2019-11-25
@cloudz

environment variables in create react app must start with REACT_APP_,
then they will be pulled into the project when building.
https://create-react-app.dev/docs/adding-custom-en...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question