【问题标题】:Angular 6 ng build --prod not creating dist folderAngular 6 ng build --prod 不创建 dist 文件夹
【发布时间】:2019-04-06 12:46:19
【问题描述】:

嗨,我是 Angular 6 的新手,我正在尝试将我的 Angular 6 应用程序放到服务器上,我正在查看 angular.io 网站文档中提供的文档,该文档说我必须执行 ng build --prod 这将创建/dist 文件夹,我需要将该文件夹复制到服务器中,但在我的情况下,/dift 文件夹本身并没有在我创建 ng build --prod, Thanx 时创建。

ng build --prod

Date: 2018-11-02T09:05:15.509Z
Hash: 73a702a04d7ddf767a38
Time: 33823ms
chunk {scripts} scripts.0f47d3fbd6308206eae4.js (scripts) 599 kB  [rendered]
chunk {0} runtime.a66f828dca56eeb90e02.js (runtime) 1.05 kB [entry] 
[rendered]
chunk {1} styles.0dacd1919fea938bb6af.css (styles) 424 kB [initial] 
[rendered]
chunk {2} polyfills.47128b287f32f00ed880.js (polyfills) 130 bytes [initial] 
[rendered]
chunk {3} main.179049c6a74691736097.js (main) 128 bytes [initial] [rendered]

angular.json

{
 "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
   "newProjectRoot": "projects",
   "projects": {
    "incident-management": {
     "root": "",
      "sourceRoot": "src",
       "projectType": "application",
       "prefix": "app",
       "schematics": {},
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/incident-management",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "node_modules/@clr/icons/clr-icons.min.css",
          "node_modules/@clr/ui/clr-ui.min.css",
          "src/styles.css"
        ],
        "scripts": [
          "node_modules/@webcomponents/custom-elements/custom-elements.min.js",
          "node_modules/@clr/icons/clr-icons.min.js"
        ]
      },
      "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
        }
      }
    },
    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "incident-management:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "incident-management:build:production"
        }
      }
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "incident-management:build"
      }
    },
    "test": {
      "builder": "@angular-devkit/build-angular:karma",
      "options": {
        "main": "src/test.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.spec.json",
        "karmaConfig": "src/karma.conf.js",
        "styles": [
          "src/styles.css"
        ],
        "scripts": [],
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ]
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": [
          "src/tsconfig.app.json",
          "src/tsconfig.spec.json"
        ],
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
},
"incident-management-e2e": {
  "root": "e2e/",
  "projectType": "application",
  "architect": {
    "e2e": {
      "builder": "@angular-devkit/build-angular:protractor",
      "options": {
        "protractorConfig": "e2e/protractor.conf.js",
        "devServerTarget": "incident-management:serve"
      },
      "configurations": {
        "production": {
          "devServerTarget": "incident-management:serve:production"
        }
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": "e2e/tsconfig.e2e.json",
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
 }
 },
 "defaultProject": "incident-management"
}

tsconfig.json

{
 "compileOnSave": false,
  "compilerOptions": {
   "baseUrl": "./",
   "outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
  "node_modules/@types"
],
"lib": [
  "es2017",
  "dom"
]

} }

【问题讨论】:

  • 这些信息不足以帮助您。您需要根据您的版本显示您的 .angular-cli.json 或 .angular.json 文件。
  • 您确定它没有创建dist 文件夹吗?没有错误,因此没有理由丢失。
  • @ user184994 谢谢,如果有错误它不会创建是吗?
  • @cenk ebret 谢谢我用文件更新了我的问题
  • 您从哪个路径运行此命令。 angular.json 中没有错误。我用我的替换了提供的 angular.json。并检查。删除"styles": [ "node_modules/@clr/icons/clr-icons.min.css", "node_modules/@clr/ui/clr-ui.min.css", "src/styles.css" ], "scripts": [ "node_modules/@webcomponents/custom-elements/custom-elements.min.js", "node_modules/@clr/icons/clr-icons.min.js" ] 后,构建工作正常。在 dist/事件管理中

标签: angular typescript angular6


【解决方案1】:
ng build --prod --base-href /portalName/

/portalName/ 应该是您的主机应用程序名称

【讨论】:

  • 嗨,是否有必要提供 --base-href /portalName/ 因为 angular.io 文档没有说要这样做.. 我想要做的是复制 dist 文件夹并将其保存在服务器上并从那里运行 ng-serve 有可能吗?
  • @vinaykhegde ng serve 供开发人员使用。构建应用程序后(使用ng build),您将不再使用ng serve。相反,您可以使用您的服务器的 HTTP 服务器(例如 Apache 或 Nginx)来服务它。
  • --base-href /portalName/ 意味着实际上您正在为该门户构建它,它还将为该门户创建一个 dist
猜你喜欢
  • 1970-01-01
  • 2018-01-02
  • 2017-11-12
  • 2017-07-27
  • 1970-01-01
  • 2020-08-06
  • 1970-01-01
  • 1970-01-01
  • 2019-02-28
相关资源
最近更新 更多