The "scripts" property of the package.json file supported by npm.
The "scripts" property of the package.json file is a dictionary containing script commands that are run at various times in the lifecycle of your package. The key is the lifecycle event, and the value is the command to run at that point.
npm supports the "scripts" property of the package.json file, for the following scripts:
- prepublish: Run BEFORE the package is packed and published, as well as on local
npm install
without any arguments. (See below) - prepare: Run both BEFORE the package is packed and published, and on local
npm install
without any arguments (See below). This is run AFTERprepublish
, but BEFOREprepublishOnly
. - prepublishOnly: Run BEFORE the package is prepared and packed, ONLY on
npm publish
. (See below.) - prepack: run BEFORE a tarball is packed (on
npm pack
,npm publish
, and when installing git dependencies) - postpack: Run AFTER the tarball has been generated and moved to its final destination.
- publish, postpublish: Run AFTER the package is published.
- preinstall: Run BEFORE the package is installed
- install, postinstall: Run AFTER the package is installed.
- preuninstall, uninstall: Run BEFORE the package is uninstalled.
- postuninstall: Run AFTER the package is uninstalled.
- preversion: Run BEFORE bumping the package version.
- version: Run AFTER bumping the package version, but BEFORE commit.
- postversion: Run AFTER bumping the package version, and AFTER commit.
- pretest, test, posttest: Run by the
npm test
command. - prestop, stop, poststop: Run by the
npm stop
command. - prestart, start, poststart: Run by the
npm start
command. - prerestart, restart, postrestart: Run by the
npm restart
command. Note:npm restart
will run the stop and start scripts if norestart
script is provided. - preshrinkwrap, shrinkwrap, postshrinkwrap: Run by the
npm shrinkwrap
command.
Additionally, arbitrary scripts can be executed by running npm run-script <stage>
. Pre and post commands with matching names will be run for those as well (e.g. premyscript
, myscript
, postmyscript
). Scripts from dependencies can be run with npm explore <pkg> -- npm run <stage>
.
To find more information :