1

I have an Angular 2 application in a subfolder of an ASP.NET project, and would like to bundle the Angular 2 application using the techniques from How to bundle an Angular app for production

The recommended approach there is to set up a project using Angular CLI. However I am having some trouble using that approach since it makes some assumptions about the project structure.

Assuming that the Angular 2 application is located in the subfolder /Angular2App/ it seems Angular CLI would like the index.html to be located in /Angular2App/src/, and when bundling the result is located in /Angular2App/dist/ and all references there from that folder's index.html assume that bundles are located at /.

However I would simply like the Angular 2 application to be available at /Angular2App/.

Any ideas as to how I can configure Angular CLI in this way?

Community
  • 1
  • 1
Svein Fidjestøl
  • 3,106
  • 2
  • 24
  • 40
  • 1
    in the angular-cli.json file you have the settings like "apps": [ { "root": "src", "outDir": "dist", "assets": ["assets"], "index": "index.html", "main": "main.ts", "polyfills": "polyfills.ts", "tsconfig": "tsconfig.json", "prefix": "app", "mobile": false, "styles": [ "scss/style.scss" ], ..try to change there – federico scamuzzi Mar 29 '17 at 07:21

2 Answers2

3

You should set deployUrl when you build your angular application and then all path variables will have prefix /Angular2App/. For example;

ng build --deployUrl "/Angular2App/"
ulubeyn
  • 2,761
  • 1
  • 18
  • 29
1

Use the base-href flag to set a base url other than the root.

ng build --base-href=/Angular2App/

From the Angular docs:

If you copy the files into a server sub-folder, append the build flag, --base-href and set the appropriately.

For example, if the index.html is on the server at /my/app/index.html, set the base href to like this.

ng build --base-href=/my/app/

You'll see that the is set properly in the generated dist/index.html.

https://angular.io/guide/deployment

Francisco d'Anconia
  • 2,436
  • 1
  • 19
  • 25