How to set the public path on angular 4

后端 未结 1 536
死守一世寂寞
死守一世寂寞 2021-01-18 18:16

So I need to configure the public folder of my application, in other words, I want the assets to point to my own path on the generated index file like src=\"mypublicpath/a

相关标签:
1条回答
  • 2021-01-18 19:08

    You're probably looking for the deployUrl option in Angular CLI. Your angular-cli.json would look like this.

    {
      "project": {
        "version": "1.0.0-beta.28.3",
        "name": "ng-app-manager"
      },
      "apps": [
        {
          "root": "src",
          "outDir": "..\/bundles\/ng-app-manager",
          "deployUrl": "http://my.cdn.host.com/assets",
          "assets": [
            "assets",
            "favicon.ico"
          ],
          "index": "index.html",
          "main": "main.ts",
          "polyfills": "polyfills.ts",
          "test": "test.ts",
          "tsconfig": "tsconfig.json",
          "prefix": "app",
          "styles": [
            "styles.css"
          ],
          "scripts": [
    
          ],
          "environments": {
            "source": "environments\/environment.ts",
            "dev": "environments\/environment.ts",
            "prod": "environments\/environment.prod.ts"
          }
        }
      ],
      "e2e": {
        "protractor": {
          "config": ".\/protractor.conf.js"
        }
      },
      "lint": [
        {
          "files": "src\/**\/*.ts",
          "project": "src\/tsconfig.json"
        },
        {
          "files": "e2e\/**\/*.ts",
          "project": "e2e\/tsconfig.json"
        }
      ],
      "test": {
        "karma": {
          "config": ".\/karma.conf.js"
        }
      },
      "defaults": {
        "styleExt": "css",
        "prefixInterfaces": false,
        "inline": {
          "style": false,
          "template": false
        },
        "spec": {
          "class": false,
          "component": true,
          "directive": true,
          "module": false,
          "pipe": true,
          "service": true
        }
      }
    }
    

    Running ng build will then automatically prefix resource references in the dist folder, with http://my.cdn.host.com/assets. For example, the reference for app.js will into http://my.cdn.host.com/assets/app.js.

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