ng build --prod --aot在Angular 6中不起作用

时间:2019-03-25 12:03:55

标签: angular deployment build

这是我的本地Angular版本详细信息。

Angular CLI: 6.1.5
Node: 10.15.1
OS: darwin x64
Angular: 6.1.6

我正在尝试使用以下命令在服务器中部署生产代码。

ng build --prod --aot

我正在获取所有文件的dist文件夹。但是当我将代码上传到服务器中时。它仍然显示Angular正在开发代码中运行。

这是我的angular.json文件。

    {
      "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
      "version": 1,
      "newProjectRoot": "projects",
      "projects": {
        "matngular": {
          "root": "",
          "sourceRoot": "src",
          "projectType": "application",
          "architect": {
            "build": {
              "builder": "@angular-devkit/build-angular:browser",
              "options": {
                "outputPath": "dist",
                "index": "src/index.html",
                "main": "src/main.ts",
                "tsConfig": "src/tsconfig.app.json",
                "polyfills": "src/polyfills.ts",
                "assets": [
                  "src/assets",
                  "src/favicon.ico",
                  "src/homepage.html",
                  "src/login.html",
                  "src/register.html",
                  "src/forgot-password.html",
                ],
                "styles": [
                  "src/assets/css/prism.min.css",
                  "node_modules/sweetalert2/dist/sweetalert2.min.css",
                  "src/assets/css/wizard.css",
                  "src/assets/css/quill.snow.css",
                  "src/assets/css/quill.bubble.css",
                  "src/assets/css/hopscotch.css",
                  "node_modules/nouislider/distribute/nouislider.min.css",
                  "node_modules/angular-calendar/scss/angular-calendar.scss",
                  "node_modules/dragula/dist/dragula.css",
                  "node_modules/ngx-toastr/toastr.css",
                  "node_modules/videogular2/fonts/videogular.css",
                  "node_modules/@swimlane/ngx-datatable/release/index.css",
                  "node_modules/@swimlane/ngx-datatable/release/assets/icons.css",
                  "src/assets/css/demo.css",
                  "src/assets/sass/app.scss",
                  "src/styles.css"
                ],
                "scripts": [
                  "node_modules/jquery/dist/jquery.min.js",
                  "src/assets/vendor/pace/pace.min.js",
                  "src/assets/js/perfect-scrollbar.jquery.min.js"
                ]
              },
              "configurations": {
                "production": {
                  "optimization": true,
                  "outputHashing": "all",
                  "sourceMap": false,
                  "extractCss": true,
                  "namedChunks": false,
                  "aot": true,
                  "extractLicenses": true,
                  "vendorChunk": false,
                  "buildOptimizer": true,
                  "fileReplacements": [
                    {
                      "replace": "src/environments/environment.ts",
                      "with": "src/environments/environment.prod.ts"
                    }
                  ]
                }
              }
            },
            "serve": {
              "builder": "@angular-devkit/build-angular:dev-server",
              "options": {
                "browserTarget": "matngular:build",
                "sslKey": "/server.key",
                "sslCert": "/server.crt",
              },
              "configurations": {
                "production": {
                  "browserTarget": "matngular:build:production"
                }
              }
            },
            "extract-i18n": {
              "builder": "@angular-devkit/build-angular:extract-i18n",
              "options": {
                "browserTarget": "matngular:build"
              }
            },
            "test": {
              "builder": "@angular-devkit/build-angular:karma",
              "options": {
                "main": "src/test.ts",
                "karmaConfig": "./karma.conf.js",
                "polyfills": "src/polyfills.ts",
                "tsConfig": "src/tsconfig.spec.json",
                "scripts": [
                  "node_modules/jquery/dist/jquery.min.js",
                  "src/assets/vendor/pace/pace.min.js",
                  "src/assets/js/perfect-scrollbar.jquery.min.js"
                ],
                "styles": [
                  "src/assets/css/prism.min.css",
                  "node_modules/sweetalert2/dist/sweetalert2.min.css",
                  "src/assets/css/wizard.css",
                  "src/assets/css/quill.snow.css",
                  "src/assets/css/quill.bubble.css",
                  "src/assets/css/hopscotch.css",
                  "node_modules/ng2-toastr/bundles/ng2-toastr.min.css",
                  "node_modules/nouislider/distribute/nouislider.min.css",
                  "node_modules/angular-calendar/scss/angular-calendar.scss",
                  "node_modules/dragula/dist/dragula.css",
                  "node_modules/videogular2/fonts/videogular.css",
                  "node_modules/@swimlane/ngx-datatable/release/index.css",
                  "node_modules/@swimlane/ngx-datatable/release/assets/icons.css",
                  "src/assets/css/demo.css",
                  "src/assets/sass/app.scss",
                  "src/styles.css"
                ],
                "assets": [
                  "src/assets",
                  "src/favicon.ico"
                ]
              }
            },
            "lint": {
              "builder": "@angular-devkit/build-angular:tslint",
              "options": {
                "tsConfig": [
                  "src/tsconfig.app.json",
                  "src/tsconfig.spec.json"
                ],
                "exclude": [
                  "**/node_modules/**/*"
                ]
              }
            }
          }
        },
        "matngular-e2e": {
          "root": "",
          "sourceRoot": "",
          "projectType": "application",
          "architect": {
            "e2e": {
              "builder": "@angular-devkit/build-angular:protractor",
              "options": {
                "protractorConfig": "./protractor.conf.js",
                "devServerTarget": "matngular:serve"
              }
            },
            "lint": {
              "builder": "@angular-devkit/build-angular:tslint",
              "options": {
                "tsConfig": [
                  "e2e/tsconfig.e2e.json"
                ],
                "exclude": [
                  "**/node_modules/**/*"
                ]
              }
            }
          }
        }
      },
      "defaultProject": "matngular",
      "schematics": {
        "@schematics/angular:component": {
          "prefix": "app",
          "styleext": "scss"
        },
        "@schematics/angular:directive": {
          "prefix": "app"
        }
      }
    }

还有其他方法可以构建应用并上传以进行生产吗?

我的环境文件夹中有2个文件

environment.prod.ts
environment.ts 

这是environment.prod.ts文件

export const environment = {
production: true,
baseUrl: 'https://app.website.com/api',
domain: 'https://app.website.com'
 };

这是environment.ts文件

export const environment = {
production: true,
baseUrl: 'https://localhost:4200/api',
domain: 'https://localhost:4200'
 };

当我在服务器中运行它时,将调用localhost url而不是网站url。

0 个答案:

没有答案