how to change the dist-folder path in angular-cli after 'ng build'

后端 未结 10 557
无人及你
无人及你 2020-12-07 11:27

I would like to use angular-cli with asp.net core and I need to know how I can change the path of the dist folder

相关标签:
10条回答
  • 2020-12-07 11:55

    Angular CLI now uses environment files to do this.

    First, add an environments section to the angular-cli.json

    Something like :

    {
      "apps": [{
          "environments": {
            "prod": "environments/environment.prod.ts"
          }
        }]
    }
    

    And then inside the environment file (environments/environment.prod.ts in this case), add something like :

    export const environment = {
      production: true,
      "output-path": "./whatever/dist/"
    };
    

    now when you run :

    ng build --prod
    

    it will output to the ./whatever/dist/ folder.

    0 讨论(0)
  • 2020-12-07 11:57

    Beware: The correct answer is below. This no longer works

    Create a file called .ember-cli in your project, and include in it these contents:

    {
       "output-path": "./location/to/your/dist/"
    }
    
    0 讨论(0)
  • 2020-12-07 12:00

    You can update the output folder in .angular-cli.json:

    "outDir": "./location/toYour/dist"
    
    0 讨论(0)
  • 2020-12-07 12:04

    Caution: Angular 6 and above!


    For readers with an angular.json (not angular-cli.json) the key correct key is outputPath. I guess the angular configuration changed to angular.json in Angular 6, so if you are using version 6 or above you most likely have a angular.json file.

    To change the output path you have to change outputPath und the build options.

    example angular.json

    {
        "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
        "version": 1,
        "projects": {
            "angular-app": {
                "projectType": "application",
                [...]
                "architect": {
                    "build": {
                        "builder": "@angular-devkit/build-angular:browser",
                        "options": {
                            "outputPath": "dist/angular-app",
                            "index": "src/index.html",
                            "main": "src/main.ts",
                            [...]
    

    I could not find any official docs on this (not included in https://angular.io/guide/workspace-config as I would have expected), maybe someone can link an official resource on this.

    0 讨论(0)
  • 2020-12-07 12:05

    for github pages I Use

    ng build --prod --base-href "https://<username>.github.io/<RepoName>/" --output-path=docs
    

    This is what that copies output into the docs folder : --output-path=docs

    0 讨论(0)
  • 2020-12-07 12:11

    The more current way of this is to update the outDir property in .angular-cli.json.

    The ng buildcommand argument --output-path (or -op for short) is still supported also, which can be useful if you want multiple values, you can save them in your package.json as npm scripts.

    Beware: The .angular-cli.json property is NOT called output-path like the currently-accepted answer by @cwill747 says. That's the ng build argument only.

    It's called outDir as mentioned above, and it's a under the apps property.

    .

    P.S.

    (December 2017)

    1-year after adding this answer, someone added a new answer with essentially same information, and the Original Poster changed the accepted answer to the 1-year-late answer containing same information in the first line of this one.

    0 讨论(0)
提交回复
热议问题