question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat(serve): Add -main flag for entry point

See original GitHub issue

Feature requested

Would like to be able to change the main entry point script to use via a flag when running ng serve (as well as ng build).

ng serve -main main2.ts -e=someOtherEnvironment

Reason

While leveraging environment constants are handy to conditionally run code in your main.ts script, they don’t get used by webpack (or AOT). So if you have some environment code that you don’t want to include in your production build and you do the following in your main.ts:

. . .
if (environment.someOtherEnvironment) {
  myBootstrap(); // This function has imports that bring in other non-production code
} else {
  platformBrowserDynamic().bootstrapModule(AppModule);
}

Webpack will follow that function and its imports and will add that code to the bundles even when you ng serve or ng build.

Having the ability to target different main scripts would allow for ng serve and ng build to be used to build the appropriate code.

Then we could create different main files: main.ts

. . .
platformBrowserDynamic().bootstrapModule(AppModule);

main.other.ts

. . .
myBootstrap();

And achieve optimal bundling of our app code based on our intended environment.

Notes

I’d be more than happy to add this feature, just want to confirm that it is something that people would feel would be worthy.

@hansl @robwormald

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:31 (19 by maintainers)

github_iconTop GitHub Comments

12reactions
filipesilvacommented, Jan 15, 2017

@SamVerschueren would this not work?

Essentially exporting Dev/Prodmodule as AppModule from within the environment file, and loading it in main.ts.

// main.ts
import './polyfills.ts';

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment, AppModule } from './environments/environment';

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);
// environments/environment.ts
export { DevModule as AppModule } from '../app/dev.module';

export const environment = {
  production: false
};
// environments/environment.prod.ts
export { ProdModule as AppModule } from '../app/prod.module';

export const environment = {
  production: false
};
4reactions
FabioAntunescommented, Jan 11, 2017

I just came across this question on stackverflow, that seems to be a perfect example why this might be useful

Read more comments on GitHub >

github_iconTop Results From Across the Web

Tutorial for using feature flags in a .NET Core app
These libraries allow you to declaratively add feature flags to your ... The Azure App Configuration service provides a dedicated portal UI ...
Read more >
Feature Toggles (aka Feature Flags) - Martin Fowler
Feature Toggles (often also refered to as Feature Flags) are a powerful technique, allowing teams to modify system behavior without changing code.
Read more >
Git Feature Branch Workflow | Atlassian Git Tutorial
This checks out a branch called new-feature based on main , and the -b flag tells Git to create the branch if it...
Read more >
Flag Code FAQ part 1: general questions - USHistory.org
Can I fly my flag at home 24 hours a day? Yes, provided it is "properly illuminated." Section 6a: "It is the universal...
Read more >
14 CFR Part 121 -- Operating Requirements: Domestic, Flag ...
ETOPS Entry Point means the first point on the route of an ETOPS flight, ... to reconsider the notice with the Executive Director,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found