Note: for support questions, please use one of these channels:
https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/
After updating to the newest release, I see that IONIC_ENV is not being set anymore.
It should be set to either dev/prod depending on which mode the build is run in.
Steps to reproduce:
1.
2.
3.
I currently use it in a custom Rollup config file:
// For reference, check the following:
// https://github.com/driftyco/ionic-app-scripts/blob/master/config/rollup.config.js
// Config borrowed from: https://github.com/driftyco/ionic-cli/issues/1205#issuecomment-255744604
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const globals = require('rollup-plugin-node-globals');
const builtins = require('rollup-plugin-node-builtins');
const json = require('rollup-plugin-json');
// We will use the machine ip to make HTTP requests to the local machine from an external device while in dev mode.
const ip = require('ip');
// We use the replace plugin to provide the correct env variables
const replace = require('rollup-plugin-replace');
console.log(process.env.IONIC_ENV, process.env)
// https://github.com/rollup/rollup/wiki/JavaScript-API
const config = {
/**
* entry: The bundle's starting point. This file will
* be included, along with the minimum necessary code
* from its dependencies
*/
entry: process.env.IONIC_APP_ENTRY_POINT,
/**
* sourceMap: If true, a separate sourcemap file will
* be created.
*/
sourceMap: process.env.IONIC_GENERATE_SOURCE_MAP ? true : false,
/**
* format: The format of the generated bundle
*/
format: 'iife',
/**
* dest: the output filename for the bundle in the buildDir
*/
dest: process.env.IONIC_OUTPUT_JS_FILE_NAME,
/**
* plugins: Array of plugin objects, or a single plugin object.
* See https://github.com/rollup/rollup/wiki/Plugins for more info.
*/
plugins: [
builtins(),
commonjs(),
nodeResolve({
module: true,
jsnext: true,
main: true,
browser: true,
extensions: ['.js']
}),
globals(),
json(),
replace({
values: {
'{{API_HOST}}': process.env.IONIC_ENV === 'prod' ? 'https://test-api.herokuapp.com' : `http://${ip.address()}:8888`
},
// Config
exclude: 'node_modules/**'
})
]
};
module.exports = config;
Which @ionic/app-scripts version are you using?
0.0.47
Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)
As a workaround I use:
// NOTE: If IONIC_ENV is not set, we check if the CLI args contain the '--prod' flag.
function isProd() {
return process.env.IONIC_ENV === 'prod' || process.argv.slice(2)
.some((arg) => arg.indexOf('--prod') !== -1)
}
It works fine, though ideally IONIC_ENV should suffice.
Can confirm. IONIC_ENV is not set for me as well.
Please forgive my rant.. but app-scripts are the worst, really the worst part of ionic and we as a development team suffer big time because of them over and over again.
I can also confirm that IONIC_ENV is not set. This is kind of a big deal, is anyone tracking this at Ionic?
This is in master, I'll close tomorrow when we publish 0.0.48.
Thanks,
Dan
Thank you very much for your fast response time!
It was an internal miscommunication. We were going to deprecate it (we did, in fact :)) but we decided now to keep it after all.
Thanks,
Dan
This will land in 0.0.48 today.
Thanks,
Dan
Hi all,
This is resolved in 0.0.48 which was just published.
Please let me know if you have any issues.
Thanks,
Dan
This one works as well 馃憤
I am using 0.0.48, but still it is not working. I am using this command ionic build --prod but the env is still dev. Even the temporary solution mentioned by @rolandjitsu (isProd()) is not working because process.argv does not list the --prod argument. Any help? Thanks
You should really update. 0.0.48 is old. 1.1.1 is the latest.
Thanks,
Dan
I am using 1.1.4 and it is not working. For example I use "ionic-app-scripts build --prod" but the IONIC_ENV is undefined. Tried setting the source directory and it is also undefined.
For me this feature seems to be broken.
https://github.com/driftyco/ionic-app-scripts/blob/master/src/util/config.spec.ts#L68
https://github.com/driftyco/ionic-app-scripts/blob/master/src/util/config.spec.ts#L166
It should be set correctly. Our tests around that pass. How are you trying to use it?
Thanks,
Dan
Thanks for the quick response. So maybe I am wrong. Can I use the ENV in Hooks? Because I am setting the src_dir in the package.json like this:
"config": {
"ionic_src_dir": "./hello"
}
And it doesn't work. When I call process.env in the hook code it won't show me any Ionic Environment Variables.
Most helpful comment
It was an internal miscommunication. We were going to deprecate it (we did, in fact :)) but we decided now to keep it after all.
Thanks,
Dan