【问题标题】:Angular CLI build without index.html没有 index.html 的 Angular CLI 构建
【发布时间】:2019-01-21 07:44:20
【问题描述】:

我们所有的 Angular 应用程序都在其他应用程序中引导(.jsp 文件加载 javascript 文件并包含 <app-root> 标记),因此我们不需要 index.html**。

但是,当我从 angular.json 中删除 index 属性时,它给了我错误:

数据路径“”应该具有必需的属性“索引”。

如果我把它留空,它确实会构建,但我收到错误:

...
95% 发出 index-html-webpack-pluginEISDIR:对目录的非法操作,请阅读
错误:EISDIR:对目录的非法操作,读取

如何在没有index.html 的情况下执行ng build

** 我们的部署过程现在实际上将index.html 复制到我们的CDN,这是不需要的,因为我们根本不想将这些文件提供给最终用户,index.html 仅在@987654330 期间用于开发人员@

【问题讨论】:

  • 您需要 index.html 文件,因为它包含元数据和位
  • @Aerus,恐怕你必须调查和修改来自 node_modules\@angular-devkit\build-angular\src\angular-cli 的文件 index-html-webpack-plugin.js -files\plugins 或其他类似
  • 这有点烦人,但我也不需要索引页面,因为我的项目仅用于构建自定义元素。感觉能够删除索引页面应该是这些类型场景的一个选项。

标签: angular angular-cli angular6 angular-cli-v6


【解决方案1】:

您可以在package.jsonscripts 部分中连接命令。因此,附加一个删除命令并创建类似这样的内容(Windows 命令;使其适应您的系统):

"scripts": {
   "build prod": "ng build --prod --env=prod -op dist && del dist\\index.html"
}

【讨论】:

    【解决方案2】:

    如果有人仍然遇到同样的问题,我就是这样解决的。

    在你的angular.json:

    "architect": {
      "build": {
        ...
        "configurations": {
          "production": {
            "index": "", // Do not copy index.html
            ...
    

    ng build --prod 不会复制 HTML 文件,而 ng buildng serve 将继续按预期使用它。

    【讨论】:

    • 我浪费了很多时间试图解决 index.html 问题,但这是真的,我在构建中不需要它,在 prod 应用程序中加载到另一个页面中。这是一个很好的解决方法,谢谢@nebirhos
    猜你喜欢
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2018-08-15
    • 2018-11-21
    • 2017-12-06
    • 2017-09-02
    相关资源
    最近更新 更多