代码之家  ›  专栏  ›  技术社区  ›  Sam

复制所有配置共享的资源

  •  0
  • Sam  · 技术社区  · 7 年前

    在我的项目生成配置中,我有以下资产声明:

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

    然后在我的部署配置中:

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

    当使用“deploy”配置构建时,将不再部署上面声明的资产。只部署config.json文件。

    作为解决方法,我必须将这些资产添加到“deploy”中的资产数组中。这样做对吗?或者有办法避免重写资产构建声明吗?

    0 回复  |  直到 7 年前
        1
  •  0
  •   Kenana Reda    7 年前

    我不知道为什么要配置特定的部署,它已经在 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 具有所需配置

    我不确定我有没有你的问题

    推荐文章