Last active
March 22, 2017 13:37
-
-
Save keyserfaty/76ed80a52561315d9094e9c38b81961e to your computer and use it in GitHub Desktop.
Setting different environments in FE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// defaults/index.js | |
import development from './development'; | |
import production from './production'; | |
export default { | |
development, | |
production | |
}[process.env.NODE_ENV || 'development']; | |
// defaults/development.js | |
export default { | |
url: 'http://localhost:8000' | |
}; | |
// defaults/production.js | |
export default { | |
url: 'http://produrl.com' | |
}; | |
// package.json | |
{ | |
"scripts": { | |
"start:prod": "NODE_ENV=production node app.js", | |
"start": "NODE_ENV=development react-scripts start" | |
} | |
} | |
// usage in a file: | |
import api from '../defaults' | |
const getUrl = () => api.url // this should be localhost or produrl.com according to environment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment