55 days ago · 10 min read2071 words · Tech · hide · Fediverse post

Visual of the build steps to take. Note that before running npm publish ./dist you need to prepare the files in ./dist (as detailed in this post) One detail that has always bugged me about publishing a package to NPM is how build output paths like dist/ can leak into the public API. Turns out, npm publish can do it, but to make it work seamlessly in a real-world project, you need a few extra pieces in place. Let me walk you through how it works. ~ The Need: Clean imports without leaking implementation details When authoring a package, you typically have a directory layout like this: my-package/ ├── src/ │ └── index.js ├── dist/ │ └── index.js ├── package.json └── README.md Source code lives in src/, while your a build step typically spits out the distribution files into a dist/ or build/ folder. Or if your package has no build step, because you authored an ES Module in JavaScript, you can even ship src/ as-is. This detail can leak into your public API, which is something you generally…

Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town