Using assets property with build configuration to copy files

Discussão em 'Angular' iniciado por mindparse, Maio 21, 2025.

  1. mindparse

    mindparse Guest

    I am trying to make use of the assets property in my environment specific build configurations of my project.json to copy specific env config file to the root of my build output directory.

    In my default build options, I have the following:

    "targets": {
    "build": {
    "executor": "@angular-devkit/build-angular:browser",
    "outputs": ["{options.outputPath}"],
    "options": {
    "outputPath": "dist/apps/dg-pr",
    "index": "apps/dg-pr/src/index.html",
    "main": "apps/dg-pr/src/main.ts",
    "polyfills": "apps/dg-pr/src/polyfills.ts",
    "tsConfig": "apps/dg-pr/tsconfig.app.json",
    "inlineStyleLanguage": "scss",
    "stylePreprocessorOptions": {
    "includePaths": [
    "apps/dg-pr/src/assets/scss",
    "node_modules/@domgen/dgx-fe-styles-core/scss"
    ]
    },
    "assets": [
    {
    "input": "apps/dg-pr/src/assets",
    "glob": "**/*",
    "output": "assets"
    },
    {
    "input": "apps/dg-pr/src",
    "glob": "config.json",
    "output": "."
    },
    {
    "input": "apps/dg-pr/src",
    "glob": "favicon.ico",
    "output": "."
    },
    "apps/dg-pr/src/configs/domains/domestic-and-general.json"
    ],
    "styles": [
    "apps/dg-pr/src/styles.scss",
    "./node_modules/primeng/resources/components/calendar/calendar.css"
    ],
    "scripts": [],
    "allowedCommonJsDependencies": [
    "validator",
    "fast-deep-equal",
    "clone-deep"
    ]
    },


    I already have a config.json at the root of my app src directory which contains some non prod specific config entries.

    I then have a prod build configuration like so

    "prod": {
    "budgets": [
    {
    "type": "initial",
    "maximumWarning": "2mb",
    "maximumError": "2mb"
    },
    {
    "type": "anyComponentStyle",
    "maximumWarning": "10kb",
    "maximumError": "18kb"
    }
    ],
    "assets": [
    { "glob": "config.json", "input": "apps/dg-pr/deployment/prod", "output": "/" }
    ],
    "fileReplacements": [
    {
    "replace": "libs/pr/util-environment/src/lib/environment.ts",
    "with": "libs/pr/util-environment/src/lib/environment.prod.ts"
    }
    ],
    "outputHashing": "all"
    }


    However when I run a prod build, the original non prod version of config.json remains, the prod version is not copied over it.

    I must be approaching this wrong, can someone point out where please?

    BTW I came across this SO which suggested it should be possible Angular 10 FileReplacements not working for Assets

    [​IMG]

    Continue reading...

Compartilhe esta Página