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

I have an existing django project where I serve static files on top of / static / path. I am porting part of the application to angular2 to be a specific mobile version of the site.

Adding <base href="/">to index.html loads the static files. www.example.com/main.js gets 404 here. Adding <base href="/static/">to index.html loads static files correctly, but when the application loads, it changes the url to / static / (I use routers), although my url should be / order /.

there is a way to use base href as / but adding a prefix to the script and style files using angular-cli

using version ng --version

@angular/cli: 1.0.0-rc.0
node: 6.9.1
os: win32 x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.0
@angular/compiler-cli: 2.4.9
+7
2

--deploy-url . ng build --deployUrl /static/. js /static/ index.html :

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

:

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

.

+12

angular CLI 6.1.1

, --base-href

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

http://127.0.0.1:5500/dist/my-app/index.html

+1

Source: https://habr.com/ru/post/1671281/


All Articles