Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 657
Aerus Avatar asked Aug 14 '18 12:08

Aerus


People also ask

What is the use of index html in angular?

html file. Angular is a framework which allows us to create "Single Page Applications", and here the index. html is the single page which was provided by the server.

Can we change index html file in angular?

Customize Webpack Configuration in Your Angular Application Now that we've added it to our project, we can use the index transform option to modify the HTML file output, based on the environment.

What is Outputhashing in angular?

–output-hashing all — hash contents of the generated files and append hash to the file name to facilitate browser cache busting (any change to file content will result in different hash and hence browser is forced to load a new version of the file)

Can we run angular without CLI?

We will start by setting up the module loader, then use npm to install Angular and its dependencies, as well as some tools and polyfills we will need, such as the TypeScript compiler. Finally, we will create a minimal application skeleton, and write the code for bootstrapping it.


2 Answers

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.

like image 101
nebirhos Avatar answered Sep 21 '22 17:09

nebirhos


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"
}
like image 29
Jürgen Röhr Avatar answered Sep 18 '22 17:09

Jürgen Röhr