1 hour ago · 10 min read2071 words · Tech · hide · 0 comments

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…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.