Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get 'ng serve -o' to launch a page other than index.html?

Tags:

angular-cli

Our angular app will be embedded in an iframe when in production. In development, we have a file, host.html, which has an iframe whose src is the angular app's index page. We can 'ng serve' and then manually bring up host.html and it works fine.

But, 'ng serve -o' wants to open up the app index file; how do I make it open host.html instead?

like image 714
eflat Avatar asked Jun 08 '17 22:06

eflat


1 Answers

So I don't think angular cli supports opening an arbitrary page with the -o option, but you could make your own npm script that does what you want.

Try opening package.json and editing the scripts section to update the start script like so (mac version):

"scripts": {
    "ng": "ng",

    // where localhost:4200 is your dev host and port, respectively
    "start": "ng serve && open http://localhost:4200/host.html",

    "build": "ng build",
    ...
  },

Depending on what platform you're using, the script would need to be written differently:

// Windows
"start":"ng serve & start http://localhost:4200/host.html"

// Mac
"start":"ng serve && open http://localhost:4200/host.html"

// Linux 
"start":"ng serve && xdg-open http://localhost:4200/host.html"

Then, instead of using ng serve to start your app, use npm start.

Reference: used this SO answer for the platform specific open commands.

like image 135
John Avatar answered Sep 21 '22 06:09

John