Angular CLI资产文件夹未放入dist文件夹

时间:2018-09-29 15:22:06

标签: angular angular-cli-v6

我们有一个Angular 6通用应用程序。我的应用程序突然开始出现错误。实际上,资产文件夹在生产构建后不会进入dist。它工作正常,但是资产文件夹突然未复制到dist文件夹。

请帮助可能是什么情况?

3 个答案:

答案 0 :(得分:1)

  

您可以在assets的构建目标中使用angular.json数组来列出要在构建项目时原样复制的文件或文件夹。如果您认为需要排除文件,请考虑不要将其放入assets

首先,我将使用angular cli 6.x.x更新项目。然后像这样将资产路径调整到angular.json中:

"assets": [
    "src/favicon.ico",
    "src/assets",
    "src/manifest.json",
    "src/ngsw-worker-mod.js",
    "src/sitemap.xml",
    "src/robots.txt",
    "src/sitemap_video.xml"
],

然后确保您不要尝试将文件复制到项目输出路径之外。

第二种方法
如果您真的想使用node glob中的glob方法,我认为您需要确保已按照说明的文档中的说明安装它。

您可以在official documentation of assets angular cli

中查看

答案 1 :(得分:0)

下面是我的angular.json文件

{
  "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "angular.io-example": {
      "root": "",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/browser",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              },
              {
                "glob": "favicon.ico",
                "input": "src",
                "output": "/"
              },
              "src/manifest.json",
              "src/ngsw-worker-mod.js",
              "src/sitemap.xml",
              "src/robots.txt",
              "src/sitemap_video.xml"
            ],
            "styles": [
              "node_modules/videogular2/fonts/videogular.css",
              "./node_modules/font-awesome/css/font-awesome.css",
              "src/styles.css"
            ],
            "scripts": [
              "node_modules/jspdf/dist/jspdf.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"
                }
              ],
              "serviceWorker": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "angular.io-example:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "angular.io-example:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "angular.io-example: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/jspdf/dist/jspdf.min.js"
            ],
            "styles": [
              "node_modules/videogular2/fonts/videogular.css",
              "src/styles.css"
            ],
            "assets": [
              {
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              },
              {
                "glob": "favicon.ico",
                "input": "src",
                "output": "/"
              },
              "src/manifest.json"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "server": {
          "builder": "@angular-devkit/build-angular:server",
          "options": {
            "outputPath": "dist/server",
            "main": "src/main.server.ts",
            "tsConfig": "src/tsconfig.server.json"
          }
        },
        "app-shell": {
          "builder": "@angular-devkit/build-angular:app-shell",
          "options": {
            "browserTarget": "angular.io-example:build",
            "serverTarget": "angular.io-example:server",
            "route": "app-shell-path"
          }
        }
      }
    },
    "angular.io-example-e2e": {
      "root": "",
      "projectType": "application",
      "cli": {},
      "schematics": {},
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "angular.io-example:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "cli": {},
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "css"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

答案 2 :(得分:0)

我不知道是否可以为您提供帮助,但是我的angular.json资产就像

    "assets": [
      "src/favicon.ico",
      "src/assets"
    ],

没有“输入”和“输出”。 Angular-cli:6.1.3,节点10.5.0