angular - 如何在 Angular 4 上设置公共(public)路径

标签 angular angular-cli

所以我需要配置我的应用程序的公用文件夹,换句话说, 我希望 Assets 在生成的索引文件上指向我自己的路径 像 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”

最佳答案

您可能正在寻找 deployUrl Angular CLI 中的选项.你的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 .

关于angular - 如何在 Angular 4 上设置公共(public)路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43497322/

相关文章:

angular - "export ' _supportsShadowDom ' was not found in ' @angular/cdk/platform'

angular - Angular 最新版本是 V8,如何从 V6 升级到 V7?

angular - 在 .Net Core Angular 5 网站中缓存破坏 index.html

c# - 使用 FormData 将带有参数 Angular 10 的文件上传到 .Net Core Web API

angular - 找不到组件的组件工厂。 Angular2 Material 对话框

angular - 在 Angular 8 中实现 Swiper

angular - Bootstrap 不适用于我的 Angular 项目

angular - 常量是什么意思?

angular - 在 Angular 6 中使用 FormData 上传文件时出现问题

Angular - 部署后加载生产 block 文件失败