Skip to content

Instantly share code, notes, and snippets.

@micimize
Last active February 3, 2024 02:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save micimize/cebad5e0a7443374722b92cfed92f5a4 to your computer and use it in GitHub Desktop.
Save micimize/cebad5e0a7443374722b92cfed92f5a4 to your computer and use it in GitHub Desktop.
Scripts to streamline/enforce the copy and publish subdir method (https://stackoverflow.com/a/39946795/2234013). idk if copying package.json is necessary
{
"prepublishOnly": "if [[ ! $PWD =~ dist$ ]]; then npm run _dist:nopublish; fi",
"_dist:nopublish": "echo 'Use `npm run dist` instead of `npm publish`!' && exit 1",
"_dist:prep": "yarn build && cp package.json dist && cp README.md dist",
"_dist:post": "rm -f dist/package.json && rm -f dist/README.md",
"dist": "npm run _dist:prep && npm publish dist && npm run _dist:post"
}
@sandrina-p
Copy link

sandrina-p commented Oct 15, 2020

Thanks for sharing!

It almost worked in my case, the only change I add to make was the dist path:

-       "dist": "npm run _dist:prep && npm publish dist && npm run _dist:post"
+       "dist": "npm run _dist:prep && npm pack ./dist && npm run _dist:post"

@lvilasboas
Copy link

Same for me here - @sandrina-p 's fix did the trick for me.
And, after that, you just need to npm publish <tar>, where tar is the tar ball generated from npm pack ./dist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment