기본적으로 build 스크립트가 package.json 파일에서 감지되면 node.js 런타임이 npm run build를 실행합니다. 애플리케이션을 시작하기 전에 빌드 단계를 추가로 제어해야 하면 커스텀 빌드 단계를 제공할 수 있습니다. 커스텀 빌드 단계는 package.json 파일에 gcp-build를 추가하여 실행할 수 있습니다.
빌드가 npm run build 스크립트를 실행하지 않도록 하려면 다음 중 하나를 수행해야 합니다.
값이 비어 있는 gcp-build 스크립트를 package.json 파일에 추가합니다.
"gcp-build":""package.json 구성에 대한 자세한 내용은 Node.js 빌드팩 구성을 참조하세요.
이 스크립트가 실행되면 package.json 파일의 dependencies 필드와 devDependencies 필드에서 종속 항목을 사용할 수 있습니다.
커스텀 빌드 단계를 실행하면 App Engine은 선언된 프로덕션 종속 항목만 package.json 파일의 dependencies 필드에 설치하여 node_modules 폴더를 삭제한 후 다시 생성합니다.
커스텀 빌드 단계에 대해 런타임을 구성하는 방법은 Node.js 빌드팩에 대한 배포 중 커스텀 빌드 단계 수행을 참조하세요.
예
커스텀 빌드 스크립트는 CSS를 사전 처리하거나, 클라이언트 측 JavaScript를 축소하거나, 도구(예: webpack 또는 gulp)를 실행하는 등 태스크를 사전 처리하는 데 사용할 수 있습니다.
예를 들어 TypeScript를 JavaScript로 컴파일하려는 경우 package.json 파일은 다음과 같습니다. gcp-build 스크립트를 참고하세요.
{"name":"appengine-typescript","description":"An example TypeScript app running on Google App Engine.","version":"0.0.1","private":true,"license":"Apache Version 2.0","author":"Google Inc.","engines":{"node":"20.x"},"scripts":{"prepare":"npm run gcp-build","pretest":"npm run gcp-build","test":"c8 mocha -p -j 2 test/*.test.js --exit","lint":"gts lint","start":"node ./index.js","deploy":"gcloud app deploy","clean":"gts clean","compile":"tsc -p .","fix":"gts fix","build":"tsc -p .","gcp-build":"tsc -p ."},"dependencies":{"@typescript-eslint/parser":"^8.0.0","express":"^4.16.3"},"devDependencies":{"@types/express":"^4.17.17","@types/node":"^20.0.0","c8":"^10.0.0","chai":"^4.5.0","gts":"^5.0.0","mocha":"^10.2.0","typescript":"^5.0.0","wait-port":"^1.0.0"}}
정적 파일 제공
커스텀 빌드 단계 중에 파일을 생성하거나 복사할 때 App Engine은 app.yaml 파일에 정의된 static_dir 또는static_files 요소를 사용하여 앱에서 직접 이러한 정적 파일을 제공하지는 않습니다. 대신 App Engine은 커스텀 빌드 단계를 실행하기 전에 정적 파일을 표준 환경의 서빙 인프라에 업로드합니다. 커스텀 빌드 단계 중에 생성되거나 복사된 파일에 대한 모든 요청으로 인해 404 NOT FOUND HTTP 오류가 발생합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-03-06(UTC)"],[[["Node.js runtime defaults to executing `npm run build` if a `build` script exists in `package.json`, but you can implement custom build steps."],["To define a custom build process, include a `gcp-build` script in your `package.json` file, which will be executed instead of `npm run build`."],["To bypass the default `npm run build` execution, add an empty `gcp-build` script in `package.json` as `\"gcp-build\":\"\"`, or use the environment variable `GOOGLE_NODE_RUN_SCRIPTS` with an empty value."],["During custom build steps, dependencies from both `dependencies` and `devDependencies` in `package.json` are available, but afterwards, App Engine only installs production dependencies listed in `dependencies`."],["Static files generated or copied during custom build steps are not served directly by App Engine using `static_dir` or `static_files` in `app.yaml`, and accessing them will result in a `404 NOT FOUND` error."]]],[]]