没有 index.html 的 Angular CLI 构建

Aer*_*rus 8 angular-cli angular angular6 angular-cli-v6

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

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

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

如果我将其留空,它确实会构建,但会出现错误:

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

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

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

小智 8

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

在您的angular.json

"architect": {
  "build": {
    ...
    "configurations": {
      "production": {
        "index": "", // Do not copy index.html
        ...
Run Code Online (Sandbox Code Playgroud)

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