Angular use environment variables and environment variables deployment

  • Use environment variables
    • node.js environment variable can be read, in the embodiment described above process.env.mdsp_osbar_url
    • In addition to reading the operating environment (or operating system, such as Cloud Foundry) environment variables may also reads its environment variables node.js
    • node.js own environmental variables into the global level, user-level, terminal stage
  • Use environment variable deployment
    • Angular each project has a directory environments, under which environment.ts and environment.prod.ts two files are stored in different configurations when deploying to different environments, default only production: true
    • src directory under the root .angular-cli.json file is the configuration Angular all CLI commands
      • .angular-cli.json inlet is provided in the main program file name node apps
      • .angular-cli.json environment is provided an inlet disposed in the apps associated node
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico",
        {
          "glob": "**/*",
          "input": "./node_modules/sinint-application-core-spa/assets/icons/",
          "output": "./src/assets/icons/"
        }
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "./assets/css/default.theme.css",
        "styles.scss"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "../node_modules/jqueryui/jquery-ui.js"
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ]
* src根目录下的这个**main.ts**文件,其中会在production值为true时才**enableProdMode()**,这个值会让编译结果不同,提高性能,关掉些功能?
import { enableProdMode } from '@angular/core';

import { environment } from './environments/environment';

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

Guess you like

Origin www.cnblogs.com/wyp1988/p/11314345.html