【问题标题】:ng build/serve only use the `environmentSource` fileng build/serve 仅使用 `environmentSource` 文件
【发布时间】:2017-10-25 10:36:40
【问题描述】:

每当我尝试为生产环境准备构建/服务时,角度 cli 仅将 environmentSource 用于环境变量。

版本。

@angular/cli: 1.2.5
node: 8.2.1
os: win32 x64
@angular/animations: 4.0.2
@angular/common: 4.0.2
@angular/compiler: 4.0.2
@angular/core: 4.0.2
@angular/forms: 4.0.2
@angular/http: 4.0.2
@angular/platform-browser: 4.0.2
@angular/platform-browser-dynamic: 4.0.2
@angular/router: 4.0.2
@angular/cli: 1.2.5
@angular/compiler-cli: 4.0.2

.angular-cli.json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "ng2angle"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "dist",
      "assets": [
        "assets",
        "favicon.ico"
      ],
      "index": "index.html",
      "main": "main.ts",
      "polyfills": "polyfills.ts",
      "test": "test.ts",
      "tsconfig": "tsconfig.app.json",
      "testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "app/core/preloader/preloader.scss",
        "styles.scss"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.js",
        "app/core/preloader/preloader.js",
      ],
      "environmentSource": "environments/environment.ts",
      "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts"
      }
    }
  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "lint": [
    {
      "project": "src/tsconfig.app.json"
    },
    {
      "project": "src/tsconfig.spec.json"
    },
    {
      "project": "e2e/tsconfig.e2e.json"
    }
  ],
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "prefixInterfaces": false,
    "inline": {
      "style": false,
      "template": false
    },
    "spec": {
      "class": false,
      "component": true,
      "directive": true,
      "module": false,
      "pipe": true,
      "service": true
    }
  }
}

构建命令

ng build --environment=prod --no-aot
ng build --environment=prod
ng build -e=prod
ng build --prod

【问题讨论】:

  • 你正在运行什么命令来构建?
  • @IvanMladenov 我刚刚更新了我的问题。请看一看。
  • 提取environment.dev.ts 文件以用于开发并将environment.ts 文件留空
  • @IvanMladenov 是的,这解决了我的问题,你能把这个作为答案发布,所以我会接受它。

标签: angular angular-cli


【解决方案1】:

使用您的开发配置提取 environment.dev.ts 文件并将 environment.ts 文件留空

【讨论】:

  • 现在面临一个关于变量的问题,应用程序从各自的环境中获取未定义的变量`无法读取未定义的属性'auth_lock_key'
  • ng serve -e=prod/dev/staging 给出以下错误src/environments/environment.ts' is not a module.
猜你喜欢
  • 2019-12-03
  • 1970-01-01
  • 2020-04-24
  • 2018-06-15
  • 2018-04-19
  • 1970-01-01
  • 2018-02-03
  • 1970-01-01
  • 2020-01-24
相关资源
最近更新 更多