0

I am using Angular 5.2 version for my new project. I have deployed it over to the DEV location with the URL

http://XX.XX.XX.XX/myDev/app/login

when I run the ng build command

ng build -aot -ec --prod --base-href=/myDev/

Now I want to run the application for multiple clients and the URL will change to something like this

http://XX.XX.XX.XX/myDev/**Client-X**/app/login
http://XX.XX.XX.XX/myDev/**Client-Y**/app/login

Client-X & Client-Y are virtual directories in IIS.

Please suggest, how do I run this application and make the changes to the base-href while performing the ng build

In my case, i would have one deployment but different URL's pointing to the same package.

2
  • The base-href change is very conditional, what you're asking is more of a server issue than an Angular issue. Commented Aug 1, 2018 at 7:08
  • You will have problems with --base-ref and --serve-path. You must use APP_BASE_HREF to change the base ref and put the href of the script in absolute url. Maybe this mine answer to a problem about .NET can throw a few ligths of the problem stackoverflow.com/questions/50746009/… talk about the problem and a possible solution (well, I think in .NET Core, but the reason is the same) Commented Aug 1, 2018 at 7:19

2 Answers 2

2

You can use environment.ts file by creating separate environment files for each clients. Each environment should contain baseURL const variable, which will be available in the runtime code.

ng build --prod --env=environment-clientA

Hope, this helps

Sign up to request clarification or add additional context in comments.

4 Comments

That's not a scalable soln, because we might many hundred clients. The app will be same for different client with few changes relative to stylesheets and CSS.
@Karan Of course it's scalable, that's the sole purpose of environment files.
But i want to keep the enironment files only for the env related config changes such as API endpoints, folder names etc..
This works for the question stated Why would an application maintain unique CSS files per client? An application should have a single template which the design is based on, and possibly tweaked from client suggestions. Even If you do need to have custom CSS for client specific app. this still is fine, it all boils down to how you designed your components / project.
0

I am doing it using token replacement.

So when I do build production all my URLS or environment.prod.ts will have tokens #{CLIENT_URL} and so on, means that compiled/bundled files will have INVALID urls or configuration settings, also it means that without modifications (replacing) my bundle will not work.

After build I will receive Artifacts and then each deployment will be replacing and putting its own properties.

In VSTS (if you are azure user ) there is extension https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens which will replace, But you can write your own script

Benefit is that after you build solution you always deploy same version to any environment you want.

So when you deploy for customer 1 you replace in all files #{CLIENT_URL} with https://client1.com for other customer with other url.

5 Comments

When you deploy for client 1. you replace in all js files #{CLIENT_URL} to client1.com, for second to client2.com
@Karan I hope i got you problem properly. this is solution if you have multiple deployments. Because if you have one deployment but different URLs then solution would be different
My need is different. I have one deployment but different URLs for the different clients. Please suggest the solution in that.
@Karan dont have solution yet, but will try to make git example
Thanks :-) for the help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.