Reputation: 1597
I'm configuring a .NET + Angular app for debugging in VS Code, but adding the ng serve as a preLaunchTask in the launch.json file is preventing the browser from launching the site https://localhost:4200. How do I set ng serve and also have the browser launches the site https://localhost:4200 automatically?
Upvotes: 0
Views: 3341
Reputation: 15819
Below is a nice checklist of three settings files you might change to make sure your Angular application in Visual Studio Code launches in a web browser:
Visual Studio Code
can launch a browser. By default in Angular they do not. So open up /.vscode/launch.json. Add this to the "configurations" list:"configurations": [
{
"preLaunchTask": "npm: start"
...
}
packages.json
. By default the ng start
command does NOT launch a browser, and so needs the -o
or open command added to the command as so:"scripts": {
"start": "ng serve -o --ssl --ssl-cert %APPDATA%\\ASP.NET\\https\\%npm_package_name%.pem --ssl-key %APPDATA%\\ASP.NET\\https\\%npm_package_name%.key",
...
}
"angular.json" - Many times you may have Node.js running in the background and hogging port 4200. So the launch will fail. To change the default port to anything but 4200, open up angular.json
and add a new one under your "serve" settings:
"serve": {
...
"options": {
"port": 4300
}
Now, pressing Debug in VS Code will call the launch.json "preLaunch" task, call "packages" to start serving Angular under your SSL cert and open the browser, then load angular.json to choose your new port!
Upvotes: 0
Reputation: 1597
Here's an implementation that I came up with that worked. The browser is launched quickly, but the background process (ng serve) eventually catches up and loads the application on to the browser.
Upvotes: 2