Git Product home page Git Product logo

Comments (3)

Robinyo avatar Robinyo commented on July 28, 2024 1

Hi,

Have you tried setting your ENV var from the command line?

"test": "ionic-app-scripts serve",

 npm run test
 MY_ENV=test npm run test

Or try setting your ENV and running another command. For example, on macOS/Linux:

MY_ENV=test npm run clean

or Windows:

set MY_ENV=test npm run clean

Cheers
Rob

from ionic-environment-variables.

webbkvalite avatar webbkvalite commented on July 28, 2024 1

I'm using Windows.
It works well now, when first setting the variable with "set":

Updated the "scripts" in package.json (with a little extra memory for my big app):

  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "ionic:build:dev": "node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",
    "ionic:build:staging": "set MY_ENV=staging&&node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",
    "ionic:build:prod": "set MY_ENV=prod&&node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build --prod",
    "ionic:serve:dev": "ionic-app-scripts serve --port 8100",
    "ionic:serve:staging": "set MY_ENV=staging&& ionic-app-scripts serve",
    "ionic:serve:prod": "set MY_ENV=prod&& ionic-app-scripts serve",
    "watch": "ionic-app-scripts watch"
  },

Also did a little change in the webpack.config.js to suit my setup:

var chalk = require("chalk");
var fs = require('fs');
var path = require('path');
var useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');

var env = process.env.IONIC_ENV;
var myEnv = process.env.MY_ENV;

useDefaultConfig[env].resolve.alias = {
    "@app/env": path.resolve(environmentPath())
};

function environmentPath() {
    var filePath = './src/environments/environment.' + (myEnv || env) + '.ts';
    if (!fs.existsSync(filePath)) {
        console.log(chalk.red('\n' + filePath + ' does not exist!'));
    } else {
        console.log("Using " + filePath);
        return filePath;
    }
}

module.exports = function () {
    return useDefaultConfig;
};

from ionic-environment-variables.

Cacowned avatar Cacowned commented on July 28, 2024

@webbkvalite Which OS do you use?

from ionic-environment-variables.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.