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?

1
  • 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 Commented Mar 29, 2017 at 7:21

2 Answers 2

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/"
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.