Where to specify delete-output-path?
Asked Answered
D

4

11

I have a Node Express project with Angular added through Angular CLI, ie ng new.

I do not want the Angular output to wipe out the distribution folder.

I understand there is a delete-output-path parameter that can be put on the command line to ng build.

Is it possible to put this in angular-cli.json?

Or should it be in tsconfig.json? Under which property?

Diffident answered 2/4, 2018 at 7:38 Comment(0)
E
4

Yes, you can. You have to put it under defaults property of .angular-cli.json like this:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "project-name"
  },
  "apps": [
    {// app property values here}

  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {},
    "serve": {
      "port": 3000
    },
    "build": {
      "deleteOutputPath": false
    }
  }
}

If you want to learn more about this file's structure, you can go here

Hope it helps :)

Enate answered 2/4, 2018 at 8:16 Comment(1)
Would anyone know how this can be prevented in the angular CLI 6+?Mages
B
16

For Angular CLI 6+ you have to edit angular.json file. You have to set deleteOutputPath false in build options

"architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "../dist",
        "deleteOutputPath": false,   <--------------------------- put here
        "index": "src/index.html",
Bikales answered 20/10, 2018 at 8:10 Comment(9)
attempting to set this using Angular CLI 7.0.7 (and 7.1.4), I get the error Data path "" should NOT have additional properties(deleteOutputPath)Slowworm
Is there anymore something similar for this in Angular 7Smithereens
@JanneHarju It is working in my Angular 7.2.6, Angular CLI: 7.3.3Bikales
@Bikales My versions are Angular cli: 7.3.1 and for Angular 7.2.4. I must try to update and check if they are working again.Smithereens
Now I believe that I know what is wrong and where is bug. I'm using this parameter with library and I assume that yours is application. Your builder is "builder": "@angular-devkit/build-angular:browser" where mine is "builder": "@angular-devkit/build-ng-packagr:build",Smithereens
@JanneHarju Did you figure out a solution to get it to work with ng-packagr ?Trimetric
actually, @JanneHarju I think I just answered my own question. They did add that option to ng-packagr, but it's named "deleteDestPath" and it goes in the ng-package.json file, alongside "$schema"Trimetric
@HankScorpio, thanks for that comment. I think it deserves its own answer, I almost didn't see it as it was in the "show more comments" area!Saucedo
@Saucedo Yeah I hear you. It is a bit hidden down here. It's a bit of a side-question and not quite relevant to the original question. If you want to create a new question specific to ng-packagr I'd be happy to write an answer for that, for future developers.Trimetric
E
4

Yes, you can. You have to put it under defaults property of .angular-cli.json like this:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "project": {
    "name": "project-name"
  },
  "apps": [
    {// app property values here}

  ],
  "e2e": {
    "protractor": {
      "config": "./protractor.conf.js"
    }
  },
  "test": {
    "karma": {
      "config": "./karma.conf.js"
    }
  },
  "defaults": {
    "styleExt": "scss",
    "component": {},
    "serve": {
      "port": 3000
    },
    "build": {
      "deleteOutputPath": false
    }
  }
}

If you want to learn more about this file's structure, you can go here

Hope it helps :)

Enate answered 2/4, 2018 at 8:16 Comment(1)
Would anyone know how this can be prevented in the angular CLI 6+?Mages
W
3

You should specify the flag in your package.json file, under the scripts tag as follows.

   "scripts": {
     "build": "ng build --prod --deleteOutputPath=false"
  },

In the file above, the --deleteOutputPath has been set to false in the build script.

Run the script using the following command from your projects' root folder.

npm run build 
Whiffet answered 21/8, 2020 at 12:59 Comment(0)
B
0

For Angular 16 this argument works: "--delete-output-path". For example:

npx ng build --output-hashing none --aot --delete-output-path=false
Bobbery answered 16/7, 2023 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.