[SOLVED] Build APP --prod --release error


#1

When i try to run command to release the final version of my app

When using the command

 sudo ionic build ios --release --prod

to generate the final version of application, I get the message…

ionic-app-scripts 1.1.0 
build prod started ... 
clean started ... 
clean finished in 28 ms 
copy started ... 
ngc started ... 
**Failed to parse and update /Users/joe/apps/my-app/sources/src/app/main.ts content for AoT **
**            compilation. For now, the default fallback content will be used instead. Please consider updating **
**            /Users/joe/apps/my-app/sources/src/app/main.ts with the content from the following link: **
**            https://github.com/driftyco/ionic2-app-base/tree/master/src/app/main.ts** 
[...]

the content of main.ts is

    import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
    import { AppModule } from './app.module';
    import { KeycloakService } from "./keycloak.service"; // see example from  https://github.com/keycloak/keycloak/tree/master/examples/demo-template/angular2-product-app

    KeycloakService.init()
      .then(() => {
        const platform = platformBrowserDynamic();
        platform.bootstrapModule(AppModule);
      })
      .catch(() => window.location.reload());

This only happens when I run the command

ionic build ios --prod --release

Using only the command

ionic build ios --prod 

the message don’t appear but the code does not minified!

Any suggestion?


#2

You should not be modifying the main.ts in this case.

Instead of using that setup, you should be using angular’s injectables correctly.

Remove it from the main.ts and move the service init to the ngModules provider array.
Then move the init method in the keycloakService to a proper constructor


#3

Thank you for suggestion.

Already change main.ts to original version and change app.component.ts file with this implementation and now works fine :wink:


app/app.component.ts


import { KeycloakService } from './keycloak.service';
declare let Keycloak: any;

export class MyApp {

  constructor(private kc: KeycloakService, public platform: Platform)
  {

    this.platform.ready().then((readySource) => {
      //After keycloak init
          this.kc.start()
            .then(() => {
              //After keycloak init
              if (this.kc.keycloakAuth.authenticated)
              {
                  //user authenticated, continue app
              }
            })
            .catch((event) => 
            {
                console.log("Keycloak init error." + event.error);  
            });
         }

    });

}

#4

I created a simple app Ionic2 with Keycloak integration https://github.com/sergeyrolich/ionic2-keycloak


#5

Dpsmobile, could you share where you called the init method for keycloak service?

Thanks