npm install과 npm run build의 차이점은 무엇입니까?
npm install과 의 차이점은 무엇입니까 npm run build?
나는 내 프로젝트에서 때때로 npm npm install이 수행 될 때 실패하기 시작 하지만 실행 npm run build하면 잘 작동 한다는 것을 알았습니다 .
어떻게 즉이 두 가지 목표의 내부 작업을 수행 install하고 run build차이?
npm installnode_modules/작업중인 노드 프로젝트에 대한 종속성을 디렉터리에 설치합니다 . install다른 node.js 프로젝트 (모듈)를 호출 하여 프로젝트에 대한 종속성으로 설치할 수 있습니다.
npm run build은의 별칭이며 npm build"build"가 package.json 파일에서 수행하는 작업을 지정하지 않는 한 아무 작업도 수행하지 않습니다. 다른 프로젝트에서 사용하기 전에 프로젝트에 필요한 구축 / 준비 작업을 수행 할 수 있습니다.
buildbuild 에 대한 문서에 따르면 link및 install명령에 의해 호출됩니다 .
이것은 npm 링크 및 npm 설치에 의해 호출되는 배관 명령입니다.
주요 차이점은 ::
npm install 은 미리 정의 된 작업을 수행하는 npm cli-command입니다. 즉, Churro가 작성한대로 package.json 내부에 지정된 종속성을 설치합니다.
npm run command-name 또는 npm run-script command-name ( 예 : npm run build )은 또한 "command-name"대신 지정된 이름으로 사용자 지정 스크립트를 실행하도록 미리 정의 된 cli-command입니다. 따라서이 경우 npm run build 는 이름이 "build"인 사용자 지정 스크립트 명령이며 그 안에 지정된 모든 작업을 수행합니다 ( 예 : 아래 예제 package.json에 제공된 echo 'hello world' ).
주목할 점 ::
1) 한 가지 더, npm build그리고 npm run build다른 두 가지가있다 npm build등의 추로에 의해 작성 할 것이다, 그러나 npm run build사용자 정의 작업 작성된 내부를 할 것입니다package.json
2) npm build과는 npm run build동일하지 않습니다. 내가 의미하는 바는 사용자 지정 빌드 ( npm run build) 스크립트 내부에 어떤 것을 지정할 수 없으며 npm build동일한 작업을 기대할 수 없다는 것 입니다. 확인하려면 다음을 시도하십시오 package.json.
{
"name": "demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build":"echo 'hello build'"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {},
"dependencies": {}
}
실행 npm run build하고 npm build하나 하나 당신은 차이를 볼 수 있습니다. 명령에 대한 자세한 내용은 npm 문서를 참조하십시오 .
건배!!
2019 년 NPM
npm build더 이상 존재하지 않습니다. npm run build지금 전화해야합니다 . 아래에 자세한 정보가 있습니다.
TLDR;
npm install: 종속성을 설치 한 다음 필드 install에서 를 호출합니다 package.json scripts.
npm run build: 필드에서 빌드 필드를 실행합니다 package.json scripts.
NPM 스크립트 필드
https://docs.npmjs.com/misc/scripts
npm package.json스크립트 필드에 입력 할 수있는 항목이 많이 있습니다 . 스크립트의 수명주기 위에있는 위의 문서 링크를 확인하세요. 대부분은 설치, 게시, 제거, 테스트, 시작, 중지, 수축 포장, 버전 전후에 스크립트를 실행할 수있는 사전 및 사후 후크를 가지고 있습니다.
복잡한 일
npm install다음과 같지 않다npm run installnpm installpackage.json종속성을 설치 한 다음package.jsonscripts.install- (필수적으로
npm run install종속성이 설치된 후 호출합니다 .
- (필수적으로
npm run install단지를 실행package.jsonscripts.install, 그것은 종속성을 설치하지 않습니다 .npm build이전에는 유효한 명령 (과 동일npm run build) 이었지만 더 이상 그렇지 않습니다. 이제 내부 명령입니다. 실행하면 얻을npm WARN build npm build called with no arguments. Did you mean to npm run-script build?수 있습니다 : https://docs.npmjs.com/cli/build 문서에서 자세한 내용을 읽을 수 있습니다.
npm installinstalls the depedendencies in your package.json config.npm run buildruns the script "build" and created a script which runs your application - let's say server.jsnpm startruns the "start" script which will then be "node server.js"
It's difficult to tell exactly what the issue was but basically if you look at your scripts configuration, I would guess that "build" uses some kind of build tool to create your application while "start" assumes the build has been done but then fails if the file is not there.
You are probably using bower or grunt - I seem to remember that a typical grunt application will have defined those scripts as well as a "clean" script to delete the last build.
Build tools tend to create a file in a bin/, dist/, or build/ folder which the start script then calls - e.g. "node build/server.js". When your npm start fails, it is probably because you called npm clean or similar to delete the latest build so your application file is not present causing npm start to fail.
npm build's source code - to touch on the discussion in this question - is in github for you to have a look at if you like. If you run npm build directly and you have a "build" script defined, it will exit with an error asking you to call your build script as npm run-script build so it's not the same as npm run script.
I'm not quite sure what npm build does, but it seems to be related to postinstall and packaging scripts in dependencies. I assume that this might be making sure that any CLI build scripts's or native libraries required by dependencies are built for the specific environment after downloading the package. This will be why link and install call this script.
'Program Club' 카테고리의 다른 글
| 중요 메서드 'System.Web.WebPages.Razor.PreApplicationStartCode.Start ()'에 대한 'System.Web.Mvc.PreApplicationStartCode.Start ()'시도가 실패했습니다. (0) | 2020.11.27 |
|---|---|
| Maven 빌드를 Gradle로 변환하는 방법은 무엇입니까? (0) | 2020.11.27 |
| 타이머가 아직 실행 중인지 확인할 수 있습니까? (0) | 2020.11.27 |
| bash, Linux : 두 텍스트 파일 간의 차이 설정 (0) | 2020.11.26 |
| C ++의 정적 변수 (0) | 2020.11.26 |