Angular 2 profiles and tomcat

508 views Asked by At

Currently I'm running a backend springboot application and a frontend Angular2 application.

We don't want to change the code when we switch between local/development/acceptance environment, we just want to let our tomcat know which version of deployment we want to use.

For my backend I was able to follow this guide https://www.javacodegeeks.com/2012/06/spring-31-profiles-and-tomcat.html

Now I also want to do this for my frontend Angular2 application but I don't really have an idea on how to start or where to look.

Thanks

1

There are 1 answers

0
andreas On

It might not be the best answer, but one way could be this:

1) In your package.json define your different build targets (I have omitted all options except output-path for brevity), that will use different directories for their output:

"scripts": {
    "build-prod": "ng build --output-path dist-prod",
    "build-dev": "ng build --output-path dist-dev"
 }

2) Let Maven (or your other favorite build tool) build all Angular variants when you build the Servlet. Make sure all variants will be deployed with your servlet.

3) Add configs for your different environments that will add ResourceHandlers for the right path, depending on that environment. I haven't used Springboot yet so here is a Snippet from a regular Spring MVC Java Config:

@Configuration
@Profile("dev")
public class DevConfig {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/**").addResourceLocations("/dist-dev/")
                .resourceChain(true).addResolver(new PathResourceResolver());
    }

}

Hope this will help until somebody has a better idea. :-)