Adding prefix path to static files in Angular using angular-cli Adding prefix path to static files in Angular using angular-cli typescript typescript

Adding prefix path to static files in Angular using angular-cli


You can use --deploy-url to prefix path of your generated static files. ng build --deploy-url /static/. It will prefix path of js files with /static/ in generated index.html like this:

<script type="text/javascript" src="/static/inline.bundle.js"></script>

From help doc:

--deploy-url (String) URL where files will be deployed.

example:

ng build --prod --deploy-url=example.com/scripts/

Updated answer based on comments.


Using angular CLI 6.1.1

This how I do it, you need to use the build flag --base-href

Example

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

and I access the site like this http://127.0.0.1:5500/dist/my-app/index.html

Official document reference here