Angular-cli: Should "ng serve" be able to serve static html files?

Created on 27 Feb 2017  路  9Comments  路  Source: angular/angular-cli

I have a app that runs just fine with "ng serve". BUT if I try to retrieve another (static) html file that is in my src directory, I get a 304 and it just serves up the angular app again. The only way that I can see that static html file is to change the app->index value in the .angular-cli.json file. But then my angular 2 app does not run. Is "ng serve" only meant for SPA so that it CANNOT serve up separate static html files? I wanted to have some exterior (not logged in) pages with a very different look than my "app". Just trying to find the least painful way, if there is one.

Most helpful comment

Any extra files you want to include in the build/serve should be added to the assets property in .angular-cli.json.

All 9 comments

Any extra files you want to include in the build/serve should be added to the assets property in .angular-cli.json.

Thank you! works great now!

  1. ng-build with your index.html set properly with its components. (or conditional app-components)
  2. rename and copy the rendered to (for example) /src/search.html
  3. in angular.json (angular-cli.json for pre v5) find "assets":
"assets": [
"src/favicon.ico",
"src/search.html",
"src/assets"
],

browse localhost:4200/search.html
enjoy :)

source

... aaaaand restart "ng serve" so the change takes effect. :)

I have spent literally hours trying this, with long directory/file names, restarting constantly and still nothing appears for my http request either in the browser or by using HttpClient.

http://localhost:4203/badge1.html

Not sure what it could be. I am using the latest stuff:

Angular CLI: 7.0.7
Node: 8.11.4
OS: win32 x64
Angular: 7.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.10.7
@angular-devkit/build-angular 0.10.7
@angular-devkit/build-ng-packagr 0.10.7
@angular-devkit/build-optimizer 0.10.7
@angular-devkit/build-webpack 0.10.7
@angular-devkit/core 7.0.7
@angular-devkit/schematics 7.0.7
@angular/cdk 6.4.7
@angular/cli 7.0.7
@angular/material 6.4.7
@ngtools/json-schema 1.1.0
@ngtools/webpack 7.0.7
@schematics/angular 7.0.7
@schematics/update 0.10.7
ng-packagr 4.4.5
rxjs 6.3.3
typescript 3.1.6
webpack 4.19.1

did you put it in "assets" in the angular json?

I did, but actually it seems I inadvertently was not setting it up correctly. Even though my target asset is down the directory structure a bit, I was able to access it finally.

angualr.json:

        "assets": [
          "src/favicon.ico",
          "src/assets",
          "src"
        ],

Reference - finally got a '200' - yay!

http://localhost:4203/app/sample/examples/elements/badge-example/badge1.html

Thanks for making me re-look at it.

I did, but actually it seems I inadvertently was not setting it up correctly. Even though my target asset is down the directory structure a bit, I was able to access it finally.

angualr.json:

        "assets": [
          "src/favicon.ico",
          "src/assets",
          "src"
        ],

Reference - finally got a '200' - yay!

http://localhost:4203/app/sample/examples/elements/badge-example/badge1.html

Thanks for making me re-look at it.

well, now we all learned something new

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings