复制所有配置共享的资产

时间:2019-03-26 08:27:52

标签: angular angular-cli angular-cli-v7

在我的项目构建配置中,我具有以下资产声明:

"assets": [ "src/favicon.ico", "src/assets", "src/assets/fonts", "src/images", "src/web.config" ],

然后在我的部署配置中:

"deploy": { "assets": [ {"glob": "config.json", "input": "src/environments/", "output": "/"}],

使用“部署”配置进行构建时,不再声明上面声明的资产。仅config.json文件被部署。

我必须将这些资产添加到“部署”中的资产数组中,以解决此问题。这是正确的方法吗?还是有一种方法可以避免覆盖资产构建声明?

1 个答案:

答案 0 :(得分:0)

我不知道为什么要配置特定的部署,它已经在angular.json中进行了配置,您可以像提供的示例一样在此文件中添加新的配置 运行它 ng build --c=build或使用以下命令运行第二次确认 ng build --c=staging其中c代表配置

顺便说一句,您应该获得包含资产文件的dist文件夹

  "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/AngularProject",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets",
          "src/web.config",
          "src/WEB-INF"
        ],
        "styles": [
          "src/styles.scss",
          "src/assets/css/fontawesome-all.min.css",
          "src/assets/css/themify-icons.css"
        ],
        "stylePreprocessorOptions": {
          "includePaths": [
          ]
      },
        "scripts": [
          "./node_modules/jquery/dist/jquery.js",
          "./node_modules/popper.js/dist/umd/popper.min.js",
          "./node_modules/bootstrap/dist/js/bootstrap.js",
          "./node_modules/jspdf/dist/jspdf.min.js",
          "./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.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,
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "4mb",
              "maximumError": "5mb"
            }
          ]
        },
        "staging": {   // a new configuration 
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.staging.ts"
            }
          ],
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true,
          "budgets": [
            {
              "type": "initial",
              "maximumWarning": "4mb",
              "maximumError": "5mb"
            }
          ]
        }
      }
    },

要进行部署,只需使用所需的配置运行ng build

我不确定我是否遇到了你的问题