Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

feat(@angular-devkit/build-angular): pass config\command line\environment parameters to code #911

Closed
wants to merge 7 commits into from

Conversation

Flybbit
Copy link

@Flybbit Flybbit commented May 13, 2018

Add more control on build process:

  1. pass parameter known only at build stage to source code using command line argument
       or environment variable
  2. define different values in code for different apps and architects
  3. strip off some parts of code for some apps and architects

How to use

angular.json:

"defines": [
  {
    "name": "DEFINE_OPTION",
    "value": false
  },
  {
    "name": "ENV_OPTION",
    "value": "process.env.TEST_ENV_DEFINES"
  },
  {
    "name": "COMMAND_LINE_OPTION",
    "value": "customOptions.customCommandLineOption"
  },
  {
    "name": "CALC_OPTION",
    "targets": {
      "production": "283745620252 + 1",
      "development": "2 + 2"
    }
  }
]

code:

declare var DEFINE_OPTION: boolean;
declare var ENV_OPTION: string;
declare var COMMAND_LINE_OPTION: string;
declare var CALC_OPTION: number;
if (DEFINE_OPTION){
  //stripped off
}

run:

set TEST_ENV_DEFINES=env_value
ng build --_customCommandLineOption=42

Issue #10521

Flybbit added 2 commits May 13, 2018 16:48
…ment parameters to code

Add more control on build process:
1) pass parameter known only at build stage to source code using command line argument
   or environment variable
2) define different values in code for different apps and architects
3) strip off some parts of code for some apps and architects
How to use
angular.json:
"defines": [
  {
    "name": "DEFINE_OPTION",
    "value": false
  },
  {
    "name": "ENV_OPTION",
    "value": "process.env.TEST_ENV_DEFINES"
  },
  {
    "name": "COMMAND_LINE_OPTION",
    "value": "buildOptions._customCommandLineOption"
  },
  {
    "name": "CALC_OPTION",
    "targets": {
      "production": "283745620252 + 1",
      "development": "2 + 2"
    }
  }
]
code:
declare var DEFINE_OPTION: boolean;
declare var ENV_OPTION: string;
declare var COMMAND_LINE_OPTION: string;
declare var CALC_OPTION: number;
if (DEFINE_OPTION){
  //stripped off
}
run:
set TEST_ENV_DEFINES=env_value
ng build --_customCommandLineOption=42

angular/angular-cli#10521
…ment parameters to code

Add more control on build process:
1) pass parameter known only at build stage to source code using command line argument
   or environment variable
2) define different values in code for different apps and architects
3) strip off some parts of code for some apps and architects
How to use
angular.json:
"defines": [
  {
    "name": "DEFINE_OPTION",
    "value": false
  },
  {
    "name": "ENV_OPTION",
    "value": "process.env.TEST_ENV_DEFINES"
  },
  {
    "name": "COMMAND_LINE_OPTION",
    "value": "buildOptions._customCommandLineOption"
  },
  {
    "name": "CALC_OPTION",
    "targets": {
      "production": "283745620252 + 1",
      "development": "2 + 2"
    }
  }
]
code:
declare var DEFINE_OPTION: boolean;
declare var ENV_OPTION: string;
declare var COMMAND_LINE_OPTION: string;
declare var CALC_OPTION: number;
if (DEFINE_OPTION){
  //stripped off
}
run:
set TEST_ENV_DEFINES=env_value
ng build --_customCommandLineOption=42

angular/angular-cli#10521
Flybbit added 2 commits May 15, 2018 18:53
…ment parameters to code -

extract custom build options to subobject options.customOptions
…ment parameters to code

Merge remote-tracking branch 'remotes/origin/webpack-define_plugin-support' into webpack-define_plugin-support
@Flybbit Flybbit requested a review from hansl as a code owner May 15, 2018 18:36
Flybbit and others added 3 commits May 15, 2018 19:51
…ment parameters to code

use forEach instead of map to filter  custom options
…ment parameters to code

change timeouts in test
…mentparameters to code

Merge branch 'master' into webpack-define_plugin-support
@Flybbit Flybbit force-pushed the webpack-define_plugin-support branch from 35cdbe5 to a2e366e Compare May 18, 2018 12:56
@filipesilva
Copy link
Contributor

In angular/angular-cli#10521 (comment) I talked a bit about why we don't want to add this functionality and a current alternative.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants