angular8的environments使用

1.environment文件夹:

environment.ts:

export const environment = {
  production: false,
  envType: '***'
};

environment.test.ts:

export const environment = {
    production: false,
    envType: '***'
};

environment.prod.ts:

export const environment = {
  production: true,
  envType: '***'
};

 

2.修改angular.json文件 (Build下和Serve下的"configurations")

 

Build下修改:

"configurations": {
    "production": {
    "fileReplacements": [
      {
        "replace": "src/environments/environment.ts",
        "with": "src/environments/environment.prod.ts"
      }
    ],
    "optimization": true,
    "outputHashing": "all",
    "sourceMap": false,
    "extractCss": true,
    "namedChunks": false,
    "aot": true,
    "extractLicenses": true,
    "vendorChunk": false,
    "buildOptimizer": true,
    "budgets": [
      {
        "type": "initial",
        "maximumWarning": "2mb",
        "maximumError": "5mb"
      },
      {
        "type": "anyComponentStyle",
        "maximumWarning": "6kb",
        "maximumError": "10kb"
      }
    ]
  },
    "prod": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.prod.ts"
        }
      ],
      "optimization": true,
      "outputHashing": "all",
      "sourceMap": false,
      "extractCss": true,
      "namedChunks": false,
      "aot": true,
      "extractLicenses": true,
      "vendorChunk": false,
      "buildOptimizer": true,
      "budgets": [
        {
          "type": "initial",
          "maximumWarning": "2mb",
          "maximumError": "5mb"
        }
      ]
    },
    "test": {
      "fileReplacements": [
        {
          "replace": "src/environments/environment.ts",
          "with": "src/environments/environment.test.ts"
        }
      ],
      "optimization": true,
      "outputHashing": "all",
      "sourceMap": false,
      "extractCss": true,
      "namedChunks": false,
      "aot": true,
      "extractLicenses": true,
      "vendorChunk": false,
      "buildOptimizer": true,
      "budgets": [
        {
          "type": "initial",
          "maximumWarning": "2mb",
          "maximumError": "5mb"
        }
      ]
    }
}

 

Serve下修改:

"configurations": {
  "production": {
    "browserTarget": "name:build:production"
  },
  "prod": {
    "browserTarget": "name:build:prod"
  },
  "test": {
    "browserTarget": "name:build:test"
  }
}

 

3.打包:

ng build -c production 线上环境    ng b --prod -c=prod

ng build -c test 测试环境

 

 

你可能感兴趣的:(angular8,environment,angular.json)