process.env.IONIC_ENV is always empty


#1

Hello,

no matter what i try in my webpack.config.js, when i try to access the process.env.IONIC_ENV variable from my app.component it’s always undefined. I tried to expose it with the webpack.EnviromentPlugin and the webpack.DefinePlugin. Neither of them worked. I tried to set the ENV Variables in the terminal with export but they are still not available in my code.

I use the latest ionic-app-scripts 3.1.2 with ionic-cli 3.19

What am i doing wrong or is there a bug in the app-scripts?

Thanks


#2

-> I tried to set the ENV Variables in the terminal

If you want to set the ‘ELECTRON_START_URL’ environment variable on macOS or Linux:

ELECTRON_START_URL=http://localhost:8104 ionic serve --no-open --port 8104

On Windows use:

set ELECTRON_START_URL=http://localhost:8104 ionic serve --no-open --port 8104

-> when i try to access the process.env.IONIC_ENV variable

...

const env = process.env.IONIC_ENV;

if (env === 'prod' || env === 'dev') {

  useDefaultConfig[env].resolve.alias = {
    "@app": path.resolve('./src/app/'),
    "@assets": path.resolve('./src/assets/'),
    "@env": path.resolve(environmentPath()),
    "@pages": path.resolve('./src/pages/'),
    "@services": path.resolve('./src/services/'),
    "@theme": path.resolve('./src/theme/')
  };
}

...

See: https://github.com/Robinyo/big-top/blob/master/config/webpack.config.js