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

How to set .env variables? #247

Open
Tobjoern opened this issue May 9, 2022 · 3 comments
Open

How to set .env variables? #247

Tobjoern opened this issue May 9, 2022 · 3 comments

Comments

@Tobjoern
Copy link

Tobjoern commented May 9, 2022

When building my nuxt app I need to specify additional environment variables, which determine the manner in which the app is built, namely the custom variable 'IS_BUILD_AS_RENDERER'.
When I didn't use nx, I'd just execute "cross-env NODE_ENV=development IS_BUILD_AS_RENDERER=false nuxt-ts".

Is there a way to set this variable using this plugin?

Thanks for your help.

@konrad-synergy
Copy link

I've got the same issue with vue, I'd expect that during build environment variables that are set in .env file are loaded and accessible like it was with the vue-cli-service cmd. Am I doing something wrong?

@konrad-synergy
Copy link

What I did to set env variables was:

  1. I've installed webpack-dotenv module
  2. In my frontend app, in the app root folder I've added configure-webpack.js file
  3. I've added this configuration:
const webpack = require('webpack');
const Dotenv = require('dotenv-webpack');
module.exports = (config) => {

  config.plugins.push(
    new Dotenv({
      path: './apps/frontend/.env',
    })
  );

};

  1. I'm building with command
export API_URL='http://api.com' && nx build frontend

And it worked. I still struggle with CI build, but that's another matter

@gregveres
Copy link
Contributor

I am using environment variables in my app.
I have broken my large app into 3 different apps and for the dev environment, I use env vars to import the port number for the "other" apps.

Here is how I define the env vars:

In the app project directory, I create two files:
.env.development and .env.production.

In each of these files I define the variables I need:

VUE_APP_I18N_LOCALE=fr
VUE_APP_I18N_FALLBACK_LOCALE=en-us
VUE_APP_MANAGE=http://localhost:8081
VUE_APP_ADMIN=http://localhost:8082

Then in my code, I read the value:

 {
    path: '/Manage/:x+',
    beforeEnter(to: Route) {
      global.location.href = `${process.env.VUE_APP_MANAGE ?? ''}${to.fullPath}`;
    }
  },

Note that my env vars needed to start with VUE_APP because that's what the docs told me:

https://cli.vuejs.org/guide/mode-and-env.html#environment-variables

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

3 participants