生命周期scripts

221 阅读1分钟

生命周期scripts:

​打包和发布:

  • prepublish:在打包和发布包之前运行,在npm install没有任何参数的本地运行。

  • prepare:在打包和发布包之前运行,在本地npm install:没有任何参数,以及安装git依赖项时运行。

  • prepublishOnly:仅在准备和打包之前运行npm publish。

    顺序:prepublishOnly -> prepare -> prepublish

压缩:

  • prepack:压缩包前运行(npm pack,npm publish并安装git的依赖时)

  • postpack:在生成压缩包并移动到其最终目的地之后运行。

安装:

  • preinstall:包安装之前运行

  • installpostinstall:包安装后运行。

卸载:

  • preuninstalluninstall:在包卸载之前运行。

  • postuninstall:在包卸载之后运行。

更改包版本:

  • preversion, version:更改包版本前运行。

  • postversion:更改包版本后运行。

  • pretest, test, posttest:在运行npm test时会运行。

  • prestop, stop, poststop:在运行npm stop时会运行。

  • prestart, start, poststart:在运行npm start时会运行。

  • prerestart, restart, postrestart在运行npm restart时会运行。注意,如果没有提供npm restart及脚本,npm restart会运行npm stop和npm start脚本。