This is described on the NPM: npm-scripts page . This is a little mysterious, but the logic is simple.
eg. Running
npm installwill execute preinstall install postinstall prepublish- this is a rather exceptional case, prepublish only works if there are no arguments, that is, it runs locally. Also check which version of npm you are using, since prepublishwith local it is installdeprecated in 4.x in favor of another approach described in question 10074 and has a nice explanation on this blog . The thing is that npm installwithout arguments it is executed when you clone a package, and it makes sense to prepare it. But people do not like this behavior, so it was decided to break the contract into two stages. prepareruns instead prepublishduring publishing and local npm install. prepublishOnlyonly works with npm publish.
Thus,
npm publishexecute prepublish publish postpublishor prepare prepublishOnly publish postpublishon 4.x
, 6.x, npm install preinstall install postinstall prepare, npm publish prepare prepublish publish postpublish.
, preX, X, postX.