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

Is there an agreed upon way to have environment variables in the application ? #463

Closed
esperancaJS opened this issue Jan 15, 2018 · 5 comments

Comments

@esperancaJS
Copy link

In Angular-CLI they have a very straightforward way: https://github.com/angular/angular-cli/wiki/stories-application-environments

Before implementing my own solution I would like to be sure there isn't already a way that most people are using and agreeing upon.

@lukeed
Copy link
Member

lukeed commented Jan 15, 2018

You can add whatever you want via DefinePlugin:

// preact.config.js
const webpack = require('webpack');

module.exports = function (config) {
  config.plugins.push(
    new webpack.DefinePlugin({
      SECRET: JSON.stringify('my-secret'),
      PASSWORD: JSON.stringify('my-password')
    });
  );
}

A lot of people also choose to use dotenv since they're already familiar with it.

We're not opinionated on what you do because (1) it's a really personal choice and (2) there are lots and lots of options out there. 😄

@ForsakenHarmony
Copy link
Member

does dotenv work with webpack?

@joshuataylor
Copy link

I've been using https://github.com/robinvdvleuten/preact-cli-plugin-env-vars to great success.

@esperancaJS
Copy link
Author

I will just say that I'm not super happy with using .env variables for FE development.
Since in the FE there are no secrets anyway and when a new developer jumps on a FE project running npm i and npm start should get him started, while with .env variables he also has to go arround asking people for the .env files and updating them manually latter on when any url changes

@joshuataylor
Copy link

I like using env values to separate production and development URLs, or test with custom URLs. For example, I can build an environment for a PR and override the URL of our API to specialised staging URL for the PR.

It has its uses, and yes, agreed that there are no secrets in the frontend land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants