Nx IS AWESOME! I love it soo much. I have just a couple feature requests:
Otherwise, keep rocking!
Thanks @wbhob, glad you like it! In terms of your feature requests, you can actually set up your Nx Workspace to accomplish these things right now.
ng g lib assets) in your workspace, put your shared asset files in the src dir of that, and in the .angular-cli.json file in the apps array and add a glob entry for your shared assets to be used by each app:{
"input": "../../../libs/assets/src/",
"output": "assets/",
"glob": "**/*"
}
ng g lib environments) and then importing constants from those into your app environment files and merging them into your app environment constants. Add something like a sharedEnvironments const to the lib that has properties for development and production and use them in your app environments:/apps/yourapp/src/environments/environment.ts
import {sharedEnvironment} from '@nxenv/environments';
export const environment = {
production: false,
apiUrl: sharedEnvironment.development.apiUrl
};
/apps/yourapp/src/environments/environment.prod.ts
import {sharedEnvironment} from '@nxenv/environments';
export const environment = {
production: true,
apiUrl: sharedEnvironment.production.apiUrl
};
That's awesome! Thank you!
@jschwarty Could you please give me a hint on how you would then point an api in a lib to different urls?
Meaning I have a local deployed api endpoint during development (https://localhost/...) and a deployed one for production (https:example.com/...)
I cant seem to get my head wrapped around it. Using your approach from point 2 I would have to import the libs variables in every app and use a HttpsInterceptor to inject the url or something like that, but that would interfere with any other api endpoint that I would like to contact.
The other solution I can think of is importing environment into the api lib, but that would then make it useless to have it in a lib.
@FallenRiteMonk did you found any solution.
@SWGeekPD I use injection.
In a helper lib I define a InjectionToken:
export const ENVIRONMENT = new InjectionToken<{}>('Environment');
Which I then inject wherever it's needed:
constructor(@Inject(ENVIRONMENT) private environment: {}) {}
Most helpful comment
Thanks @wbhob, glad you like it! In terms of your feature requests, you can actually set up your Nx Workspace to accomplish these things right now.
ng g lib assets) in your workspace, put your shared asset files in thesrcdir of that, and in the.angular-cli.jsonfile in theappsarray and add a glob entry for your shared assets to be used by each app:ng g lib environments) and then importing constants from those into your app environment files and merging them into your app environment constants. Add something like asharedEnvironmentsconst to the lib that has properties fordevelopmentandproductionand use them in your app environments:/apps/yourapp/src/environments/environment.ts
/apps/yourapp/src/environments/environment.prod.ts