【问题标题】:How to set the public path on angular 4如何在 Angular 4 上设置公共路径
【发布时间】:2017-06-13 04:07:16
【问题描述】:

所以我需要配置我的应用程序的公用文件夹,换句话说, 我希望资产在生成的索引文件上指向我自己的路径 比如 src="mypublicpath/assets/app.js"

我很确定这是一个需要在 angular-cli.json 配置中设置的值。

这是我的文件

{
  "project": {
    "version": "1.0.0-beta.28.3",
    "name": "ng-app-manager"
  },
  "apps": [
    {
      "root": "src",
      "outDir": "../bundles/ng-app-manager",
      "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
    }
  }
}

我只需要相当于 webpacks "publicPath"

【问题讨论】:

标签: angular angular-cli


【解决方案1】:

您可能正在寻找Angular CLI 中的deployUrl 选项。你的angular-cli.json 看起来像这样。

{
  "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
    }
  }
}

运行ng build 将自动为dist 文件夹中的资源引用添加前缀http://my.cdn.host.com/assets。例如,app.js 的引用将变为 http://my.cdn.host.com/assets/app.js

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-30
    • 2016-09-08
    • 2023-03-24
    • 2016-02-16
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    相关资源
    最近更新 更多