1. 1.environment文件夹下新建一个environment.test.ts文件
    2. export const environment = {
    3. production:true,
    4. baseURL:'http://localhost:3002'
    5. }
    6. 2.angula.json文件夹中复制production字段的内容并改变
    7. "test": {
    8. "budgets": [
    9. {
    10. "type": "initial",
    11. "maximumWarning": "500kb",
    12. "maximumError": "1mb"
    13. },
    14. {
    15. "type": "anyComponentStyle",
    16. "maximumWarning": "2kb",
    17. "maximumError": "4kb"
    18. }
    19. ],
    20. "fileReplacements": [
    21. {
    22. "replace": "src/environments/environment.ts",
    23. //与production中为"with": "src/environments/environment.prod.ts"
    24. "with": "src/environments/environment.test.ts"
    25. }
    26. ],
    27. "outputHashing": "all"
    28. },
    29. serve字段下复制production字段的内容并更改
    30. "test": {
    31. "browserTarget": "test4:build:test"
    32. // ng serve --configuration=test --port 4600
    33. },
    34. 3.启动命令
    35. ng serve --configuration=test --port 4600
    36. //在4600端口下进行查看,可以看到test环境的环境变量已经改变,如下图

    image.png