Comments (3)
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.
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.
@webbkvalite Which OS do you use?
from ionic-environment-variables.
Related Issues (20)
- The Angular AoT build failed. typescript error HOT 8
- How to use with Unit testing with Karma HOT 6
- Cannot find module '@app/env'. HOT 7
- Can not find '@app/env' when running 'ionic cordova build ios' HOT 8
- TypeError: Cannot read property 'resolve' of undefined HOT 4
- Environment folder outside Angular
- Custom environment other than IONIC_ENV, is not recognized as an internal or external command HOT 2
- How to ionic serve --prod? HOT 2
- using environment variables with live deploy HOT 1
- When I build with params MY_ENV=dev and --prod, ionic builds with the prod environment. HOT 3
- Everytime its load the last environment file
- Not working HOT 3
- Cannot find module ''@app/env" only at first run
- Loading environment variables when no `environment.XXX.ts` present
- Error: Cannot find module "@app/env" HOT 4
- Production env doesn't work with run livereload
- Updating env file with new attribute is not picked up by build or serve HOT 1
- No example in how to write the enviroment variable itself HOT 1
- Error: The Angular AoT build failed
- Building Ionic for Browser --
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ionic-environment-variables.