Commit a8731d06 authored by Tim Neutkens's avatar Tim Neutkens Committed by Arunoda Susiripala

Added universal configuration example (#991)

* Added universal configuration example

* Make example more clear
parent 2e81af8d
{
"presets": [
"next/babel"
],
"plugins": [
["transform-define", "./env-config.js"]
]
}
# With universal configuration
## How to use
Download the example [or clone the repo](https://github.com/zeit/next.js):
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/basic-css
cd basic-css
```
Install it and run:
```bash
npm install
npm run dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))
```bash
now
```
## The idea behind the example
This example show how to set custom environment variables for your application based on NODE_ENV using [transform-define](https://github.com/FormidableLabs/babel-plugin-transform-define).
const prod = process.env.NODE_ENV === 'production'
module.exports = {
'BACKEND_URL': prod ? 'https://api.example.com' : 'https://localhost:8080'
}
{
"name": "with-env",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^2.0.0-beta"
},
"devDependencies": {
"babel-plugin-transform-define": "^1.2.0"
},
"author": "",
"license": "ISC"
}
/* global BACKEND_URL */
export default () => (
<div>Loading data from { BACKEND_URL }</div>
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment