When to use 'npm start' and when to use 'ng serve'?

后端 未结 5 1489
离开以前
离开以前 2020-12-02 05:19

ng serve serves an Angular project via a development server

 

npm start runs an ar

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 05:40

    From the document

    npm-start :

    This runs an arbitrary command specified in the package's "start" property of its "scripts" object. If no "start" property is specified on the "scripts" object, it will run node server.js.

    which means it will call the start scripts inside the package.json

    "scripts": {
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite --baseDir ./app --port 8001\" ",
    "lite": "lite-server",
     ...
    }
    

    ng serve:

    Provided by angular/angular-cli to start angular2 apps which created by angular-cli. when you install angular-cli, it will create ng.cmd under C:\Users\name\AppData\Roaming\npm (for windows) and execute "%~dp0\node.exe" "%~dp0\node_modules\angular-cli\bin\ng" %*

    So using npm start you can make your own execution where is ng serve is only for angular-cli

    See Also : What happens when you run ng serve?

提交回复
热议问题