// 현재 실행된 stage 값을 참조하기
// 하지만 스크립트를 따로 작성하는게 더 효율적으로 보인다.
{
"scripts": {
"dev:hello": "echo ${npm_lifecycle_event#dev:}"
}
}
- yarnpkg - Is there a way to get the name of the npm script passed to the command specified by that script? - Stack Overflow1
- scripts | npm Docs2
Footnotes
-
npm 스크립트의 이름을 얻는 방법에 대한 질문과
npm_lifecycle_event환경 변수를 사용하는 방법으로 제안 ↩ -
package.json 파일에서 스크립트를 사용하는 방법에 대한 개요, 기본 제공 환경 변수 목록도 포함 — “the
npm_lifecycle_eventenvironment variable is set to whichever stage of the cycle is being executed.” 스크립트는sh로 돌아서 bash 전용${var//a/b}대신 POSIX${var#prefix}를 쓴다 — “Scripts are run by passing the line as a script argument tosh.” ↩