in previous version i can set global constant at webpack config files and webpack will replace it when compile.
at version 1.0 it seems not use webpack, then how can i set it?
yeah. same question here.
i麓m not sure but is theme.configProvider.ts not that you looking for?
nope. that's not what we looking.
For example, we need to set different API_URL_PREFIX in the different environment.
In previous version before 1.0 we set it on webpack.dev.js or webpack.prod.js.
But this is not working after upgraded to version 1.0
You can set it over angular cli:
http://stackoverflow.com/questions/40683990/angular-2-angular-cli-set-global-variable-on-build
Hmm. I think you misunderstand my meaning.
Previously we use webpack DefinePlugin to achieve this purpose.
here's the reference: http://stackoverflow.com/questions/30030031/passing-environment-dependent-variables-in-webpack
how I set it in webpack.dev.js or webpack.prod.js:
new DefinePlugin({
'ENV': JSON.stringify(METADATA.ENV),
'HMR': METADATA.HMR,
'API_URL': JSON.stringify(METADATA.API_URL),
'process.env': {
'ENV': JSON.stringify(METADATA.ENV),
'NODE_ENV': JSON.stringify(METADATA.ENV),
'HMR': METADATA.HMR,
'API_URL': JSON.stringify(METADATA.API_URL)
}
}),
and then we can get the value directly in the application like:
return this.http.get(`${API_URL}/staff`);
but now this approach is not working due to variable undefined.
o.k example Api-url:
go for dev in the file /src/environments/environment.ts:
export const environment = {
production: false,
apiUrl: 'http://dev.env',
};
same for prod in file /src/environments/environment.ts:
export const environment = {
production: true,
apiUrl: 'http://prod.env',
};
in your Service/Componente etc:
import { environment } from '../../environments/environment';
@Injectable()
export class ...
this.apiUrl = environment.apiUrl;
dev is now default to use prod with
ng build --env=prod
or
ng serve --env=prod
i hope this is it ?
oh. this is another good solution!
Thanks @Newan !
Most helpful comment
o.k example Api-url:
go for dev in the file /src/environments/environment.ts:
same for prod in file /src/environments/environment.ts:
in your Service/Componente etc:
dev is now default to use prod with
ng build --env=prodor
ng serve --env=prodi hope this is it ?