Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of universal configuration / envs #983

Closed
rauchg opened this issue Feb 4, 2017 · 1 comment
Closed

Example of universal configuration / envs #983

rauchg opened this issue Feb 4, 2017 · 1 comment
Assignees
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@rauchg
Copy link
Member

rauchg commented Feb 4, 2017

For zeit.co we're using a really neat babel plugin called transform-define

It's basically the same that webpack does, but thanks to doing it in babel, it has advantages for next:

  • it's universal (client and server)
  • it's easier to config! (just add it to plugins inside .babelrc or package.json)

package.json:

{
  "dependencies": {
    "next": "beta",
    "babel-plugin-transform-define": "1.2.0"
  },
  "babel": {
    "presets": [
      "next/babel"
    ],
    "plugins": [
      [
        "transform-define",
        "./env-config.js"
      ]
    ]
  }
}

env-config.js:

const prod = 'production' === process.env.NODE_ENV

module.exports = {
  'MY_ENV_VARIABLE': prod
    ? 'production'
    : 'development'
}

pages/index.js

export default () => (
  <div>Hello visitor from { MY_ENV_VARIABLE }</div>
)
@rauchg rauchg added good first issue Easy to fix issues, good for newcomers Nice to have labels Feb 4, 2017
@rauchg
Copy link
Member Author

rauchg commented Feb 4, 2017

Basically this issue is for someone to create the example for examples/env-config and submit it as a PR!

@timneutkens timneutkens self-assigned this Feb 4, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants