Angular CLI build without index.html
Asked Answered
S

2

15

All our Angular applications are bootstrapped in other applications (.jsp files which load the javascript files and include the <app-root> tag), so we have no need for an index.html**.

However when I remove the index property from our angular.json it gives me the error:

Data path "" should have required property 'index'.

If I leave it empty it does build but I get the error:

...
95% emitting index-html-webpack-pluginEISDIR: illegal operation on a directory, read
Error: EISDIR: illegal operation on a directory, read

How can I perform an ng build without the index.html?

** our deploy process now actually copies the index.html to our CDN which is unwanted since we don't want to serve these files to the end users at all, the index.html is only used for developers during ng serve

Shambles answered 14/8, 2018 at 12:37 Comment(3)
you need the index.html file as it contains the meta data and bitsSalangi
@Aerus, I'm afraid you must to investigate and modify someway the file index-html-webpack-plugin.js from node_modules\@angular-devkit\build-angular\src\angular-cli-files\plugins or another likeBalf
It's a mild annoyance, but I too don't need the index page as my project is used only to build custom elements. It feels like being able to remove the index page should be an option for these types of scenarios.Hettiehetty
V
18

In case anyone is still having the same issue, this is how I solved it.

In your angular.json:

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

ng build --prod will not copy the HTML file, while ng build and ng serve will keep using it as expected.

Viaticum answered 2/6, 2020 at 20:14 Comment(1)
I wasted so many time trying to solve the index.html issue, but that's true, I don't need it in the build, in prod app is loaded in another page. This is a wonderful workaround, thanks @ViaticumRehnberg
S
2

You can concatenate commands in the scripts section of package.json. So append a delete command and create something like this (Windows command; adapt it to your system):

"scripts": {
   "build prod": "ng build --prod --env=prod -op dist && del dist\\index.html"
}
Sansculotte answered 14/8, 2018 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.