So for many many years there have been countless issues opened by people who want to run some sort of compile step before publishing their module (coffeescript -> js, babel compile, typescript compile, etc), and the npm team has consistently been unable to deliver.
They have made two attempts, prepublish, which also runs on npm install and therefore makes it useless, and prepublishOnly, which only runs after the tar has been packed and therefore has no effect on the actual published code. I am baffled as to how it could be so difficult to implement a hook that runs and is able to transform code before publishing, but alas such is life.
I guess my question is, would you be down for a PR that adds an actual build hook? We could take a task named like np-before-publish and actually execute it before publishing, and I would be more than happy to pull request this in 馃懍
You can solve that with in-publish.
Here is how I am using it in trae:
{
"scripts": {
"prepublish": "in-publish && npm run build || echo 'just installing'"
}
}
Use the version hook
{
"scripts": {
"version": "npm run build"
}
}
prepublishOnly, which only runs after the tar has been packed and therefore has no effect on the actual published code
Is that supposed to be the case? I thought that was the whole purpose of prepublishOnly. On my environment scripts that run on prepublishOnly make it into the released code.
I'm on windows 10 using npm 5.6.0 and node 8.9.4.
I think this issue can be closed if some other people can confirm that prepublishOnly works.
Most helpful comment
Use the
versionhook