I have 2 independent parts of app which use common theme (as of now).
So I tried to play around by putting them in same app but in 2 different modules: AppModule and SecondModule
Now, I created a variable buildModule in environment files and created an environment.second.ts file with value of this variable(all other environment files have different value of this variable like first, third etc):
export const environment = {
production: true,
LANGUAGE: 'en',
envName: 'second',
buildModule: 'second'
};
and an entry in angular-cli.json
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"second": "environments/environment.second.ts"
}
And in main.ts, I am trying to do conditional bootstrapping of modules:
if (environment.production) {
enableProdMode();
}
let buildModule: string = environment.buildModule;
if(buildModule === 'second'){
platformBrowserDynamic().bootstrapModule(SecondModule)
.catch(err => console.log(err));
}
else{
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
}
but I get an error:
ERROR in Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
at Object.resolveEntryModuleFromMain (C:\Others\Project\Src\webapp\multiple\node_modules\@ngtools\webpack\src\entry_resolver.js:121:15)
at Promise.resolve.then.then (C:\Others\Project\Src\webapp\multiple\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:240:54)
at <anonymous>
I came across this bug for this error: https://github.com/angular/angular-cli/issues/3540
Is there a different way to bootstrap/build modules independently in angular 5?