-
Notifications
You must be signed in to change notification settings - Fork 304
Conversation
Make a global ENV object with all the environment variables
add the plugin dependencie
@cescoferraro this is not working with |
It was working by the time I was using rollup. Webpack offers similar configuration |
I was just using your patch as inspiration and I forgot to reference the custom config file for rollup. It seems to be working just fine, the only issues are with where the builds are being placed. So may bad 👍 |
I've actually just tried this with a production build, and somehow, this env var is ignored. |
@rolandjitsu same thing for webpack. My builds are way faster var path = require('path');
var webpack = require('webpack');
// for prod builds, we have already done AoT and AoT writes to disk
// so read the JS file from disk
// for dev buids, we actually want to pass in .ts files since we
// don't have .js files on disk, they're exclusively in memory
function getEntryPoint() {
if (process.env.IONIC_ENV === 'prod') {
return '{{TMP}}/app/main.prod.js';
}
return '{{TMP}}/app/main.dev.js';
}
function getPlugins() {
console.log(process.env.IONIC_ENV);
let env = new webpack.DefinePlugin({
'process': {
'VERSION': JSON.stringify(process.env.VERSION),
'ENV': JSON.stringify(process.env.IONIC_ENV)
}
});
if (process.env.IONIC_ENV === 'prod') {
return [
// This helps ensure the builds are consistent if source hasn't changed:
new webpack.optimize.OccurrenceOrderPlugin(),env
// Try to dedupe duplicated modules, if any:
// Add this back in when Angular fixes the issue: https://github.com/angular/angular-cli/issues/1587
//new DedupePlugin()
];
}
return [env];
}
module.exports = {
entry: getEntryPoint(),
output: {
path: '{{BUILD}}',
filename: 'main.js'
},
devtool: 'source-map',
resolve: {
extensions: ['.js', '.json']
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json'
}
]
},
plugins: getPlugins(),
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
}; |
I had to switch to rollup because I get #393. But after I deployed the app to cloud and tried to use it with Ionic View I realized that somehow all my env vars are ignore and API calls were made to I think it has something to do with AOT, as I think you explain above. But do you have any idea how to make this work with prod builds? |
@rolandjitsu I think |
|
This solution does not work for prod builds due to AOT resolving values statically. So the only workaround is to use strings instead of vars. E.g.: // rollup.config.js
replace({
'{{API_URL}}': process.env.IONIC_ENV === 'dev' ? 'localhost:8000/api' : 'api.domain.com'
})
// some_file.ts
http.get('{{API_URL}}/ping') At runtime, |
solves this ionic-team/ionic-cli#1205 by adding IONIC_ENV as arollup global variable. Then you can check the environment in any typescript file like.