Aerus
Aerus

Reputation: 4380

Angular CLI build without index.html

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

Upvotes: 15

Views: 10280

Answers (2)

nebirhos
nebirhos

Reputation: 376

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.

Upvotes: 18

J&#252;rgen R&#246;hr
J&#252;rgen R&#246;hr

Reputation: 941

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

Upvotes: 2

Related Questions