Programing

'npm start'는 언제 사용하고 'ng serve'는 언제 사용합니까?

crosscheck 2020. 7. 5. 08:03
반응형

'npm start'는 언제 사용하고 'ng serve'는 언제 사용합니까?


ng serve 개발 서버를 통해 Angular 프로젝트를 제공

 

npm start"scripts"객체의 패키지 "start"속성에 지정된 임의의 명령을 실행합니다. "scripts"오브젝트에 "start"특성이 지정되지 않으면 node server.js가 실행됩니다.

ng serve내장 서버를 npm start시작하는 반면 노드 서버를 시작하는 것처럼 보입니다 .

누군가 그것에 불을 붙일 수 있습니까?


npm start파일 start에서 scripts객체 명령에 대해 정의한 모든 것을 실행 package.json합니다.

따라서 다음과 같은 경우 :

"scripts": {
  "start": "ng serve"
}

그런 다음 npm start실행 ng serve됩니다.


CLI를 사용하는 프로젝트의 경우 일반적으로 ng serve를 사용합니다. 다른 경우에는 npm start를 사용할 수 있습니다. 자세한 설명은 다음과 같습니다.

ng 봉사

프로젝트 될 것 입니다 , 특히 사용 '코너 CLI 인식'각 CLI를 사용하여 생성 된, 즉 프로젝트를 :

ng new app-name

CLI를 사용하여 프로젝트를 스캐 폴딩 한 경우에는 ng serve를 사용하고 싶을 것입니다.

npm 시작

Angular CLI를 인식 하지 못하는 프로젝트의 경우 사용할 수 있습니다 (또는 Angular CLI를 인식하는 프로젝트에 대해 'ng serve'를 실행하는 데 간단히 사용할 수 있음)

다른 답변 상태로, 이것은 식별자가 'start'인 package.json에서 npm 명령을 실행하는 npm 명령이며 'ng serve'만 실행할 필요는 없습니다. package.json에 다음과 같은 것을 가질 수 있습니다.

   "scripts": {
     "build:watch": "tsc -p src/ -w",
     "serve": "lite-server -c=bs-config.json",
     "start": "concurrently \"npm run build:watch\" \"npm run serve\""
     ...
   },
   "devDependencies": {
     "concurrently": "^3.2.0",
     "lite-server": "^2.2.2",

이 경우 'npm start'를 실행하면 다음 명령이 실행됩니다.

concurrently "npm run build:watch" "npm run serve"

이렇게하면 TypeScript 컴파일러 (코드 변경 사항 관찰)가 동시에 실행되고 노드 라이트 서버 (사용자 BrowserSync)가 실행됩니다


문서에서

npm-start :

패키지의 "scripts"객체의 "start"속성에 지정된 임의의 명령이 실행됩니다. "scripts"오브젝트에 "start"특성이 지정되지 않으면 node server.js가 실행됩니다.

즉, 패키지 내부의 시작 스크립트를 호출합니다.

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

ng 봉사 :

angular / cli에 의해 생성 된 angular2 앱을 시작하기 위해 angular / angular-cli에서 제공합니다. angular-cli를 설치하면 C:\Users\name\AppData\Roaming\npm(Windows의 경우) 아래에 ng.cmd가 생성 되고 실행됩니다."%~dp0\node.exe" "%~dp0\node_modules\angular-cli\bin\ng" %*

따라서 사용 npm start하면 ng serveangular-cli에만 있는 곳에서 자신의 실행을 할 수 있습니다

See Also : What happens when you run ng serve?


There are more than that. The executed executables are different.

npm run start

will run your projects local executable which is located in your node_modules/.bin.

ng serve

will run another executable which is global.

It means if you clone and install an Angular project which is created with angular-cli version 5 and your global cli version is 7, then you may have problems with ng build.


You should use ng serve hence npm start is a script which will run the same thing.More efficient way is directly calling ng serve over going though unnecessary script

참고URL : https://stackoverflow.com/questions/40190538/when-to-use-npm-start-and-when-to-use-ng-serve

반응형