LoginSignup
10
9

More than 5 years have passed since last update.

Angular6ではenvが指定できなくなりました。

Posted at

Angularで develop, production以外の環境を用意するときに便利だったコマンド。

ng build --prod -e=staging
ng build --prod --env=staging

これ、Angular6では使えなくなりました。

つかうと、

Unknown option: '--env'

と怒られます。

Angular6 では、 env ではなく、 configuration を指定します。

ただ、その前にいくつか準備が必要です。

Angular6の下記の部分を変更する必要があります。。

angular.json
"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
    },
    "staging": {
        "fileReplacements": [
            {
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.staging.ts"
            }
        ],
        "optimization": true,
        "outputHashing": "all",
        "sourceMap": true,
        "extractCss": true,
        "namedChunks": false,
        "aot": true,
        "extractLicenses": true,
        "vendorChunk": false,
        "buildOptimizer": true
    },
}

ここでは、 configurationsstaging を追加しています。
Angular6では、 src/environments 以下の設定以外も変更しやすいように、 environment ではなく、 configuration になりました。

この設定を適用するには、下記のように build します

ng build --configuration=staging

(ng serveなども同様)

10
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
9