0

In my project build configuration I have the following assets declaration :

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

Then in my deploy configuration :

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

When building using the "deploy" configuration, the assets declared above are no longer deployed. Only the config.json file gets deployed.

I have to add these assets to the assets array in "deploy" as a workaround. Is this the right way to do it ? Or is there a way to avoid overwriting the assets build declaration ?

Sam
  • 13,934
  • 26
  • 108
  • 194

2 Answers2

0

I couldn't know why you configure specific deploy, it's already configured in angular.json, you can add a new configuration in this file like the provided example running it by ng build --c=build or to run the second confiduration using ng build --c=staging where c stand to configuration

By the way, you should get dist folder which contain the assets files

  "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"
            }
          ]
        }
      }
    },

To Deploy, it's enough to run ng build with required config

I'm not sure if I got what is your issue

Kenana Reda
  • 430
  • 1
  • 9
  • 24
  • yes I get the dist folder with the assets files, but only if I include the build assets in the "deploy" configuration. Otherwise they are not added to the dist folder. I have to redefine the assets in the "deploy" configuration because for deployement I haave to include the config.json file (see my first post). So I'm wondering how to concatenate assets from build with assets from "deploy" configuration instead of duplicating ? – Sam Mar 26 '19 at 10:19
  • sorry couldn't catch it, but in `package.json` in `script` useing `postinstall` may achieve your requirement, Can I know How you configure Deploy? there is several ways, I've tried deploy to Azure using script in `Package.json` and you can use `Kudu` – Kenana Reda Mar 26 '19 at 11:08
0

I solved this problem with the following entry in my architect > build > options > assets >:

{
 "glob": "**/*",
 "input": "<src_base_path>/assets",
 "output": "./assets/"
}

Where src_base_path could be:

  • src: If you want to take the assets of the selected project, as indicated in this question.
  • projects/<my project>/src: When you are in a multi-project configuration and you want to select the src folder of any project.
  • dist/<my project>/src: Same as before but instead of getting the sources you get its processed version.
EliuX
  • 11,389
  • 6
  • 45
  • 40