nguyen anhtuan
nguyen anhtuan

Reputation: 83

Path of bundle file when run ng serve in angular cli

When I run ng serve I have open port localhost:4200 with js file loaded path like:

http://localhost:4200/polyfills.bundle.js

how can I change path to

http://localhost:4200/anypath/polyfills.bundle.js

Upvotes: 1

Views: 2092

Answers (4)

JamesHough
JamesHough

Reputation: 97

This is possible if you run with the ng serve parameter --baseHref=/anypath

If you run using npm start then edit the package.json file to add --baseHref=/anypath to the ng serve command.

You will also need to either change the <base href="/anypath" /> inside the index.html file or remove that base from the index file and instead provide an APP_BASE_HREF provider in your app.module.ts - an example below:

import { NgModule } from '@angular/core';
import { APP_BASE_HREF } from '@angular/common';
...
...

@NgModule({
  declarations: [
    ...
    ...
  ],
  ...
  ...
  providers: [
    {
      provide: APP_BASE_HREF,
      useValue: '/anypath,
    },
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

This works for me. I needed to debug locally simulating as though the angular site was deployed to a sub folder on the website, not the root.

Upvotes: 2

nguyen anhtuan
nguyen anhtuan

Reputation: 83

Angular Cli do not support this case, so my solution is using ng build in watch mode and config outDir in .angular-cli.json. Thank for your help

Upvotes: 0

Paullus Nava
Paullus Nava

Reputation: 70

I am not sure if I get your question correctly, but I had similar issue to use image files.

I used the "Assets" folder and everything worked fine.

UPDATE: improving answer.

If you put "polyfills.bundle.js" inside /src/assets you will be able to locate if at the following address

http://localhost:4200/assets/polyfills.bundle.js

I hope that helps you out.

Upvotes: 0

ircmgr
ircmgr

Reputation: 77

Why you want to load this path? Ng serve should just start your app normally on /

Upvotes: 0

Related Questions