NPM library best practices?
I was creating my own NPM library, @menglinmaker/soundfont3 but there are so many technical decisions:
I decided to take inspiration from a few GitHub repos like vuejs/core, solidjs/solid, mrdoob/three.js.
This is what I pickup up on:
Mostly unsure what bundler + config and testing library to use.
Eg: Apparently it's possible to unit test on a browser?
Boilerplate repo:
https://github.com/MengLinMaker/npm-library-boilerplate
- So many bundlers to choose from: esbuild, webpack, rollup, snowpack, tsup...
- Do I bundle to 1 file? Tree-shake?
- So many testing frameworks too: jest, vitest...
- So many eslint plugins.
- How do I even test if ESM and CJS imported correctly?
I decided to take inspiration from a few GitHub repos like vuejs/core, solidjs/solid, mrdoob/three.js.
This is what I pickup up on:
- Use script "preinstall" to force the use of "pnpm" for development. Very opinionated decision, but improves consistency with setup and CI.
- Use script "postinstall" to ensure git hooks are installed.
- Lint and format at least every pre-commit.
- Use "eslint-plugin-compat" to detect browser compatibility issues for web apis.
- Lack of runtime compatibility linting - does api exist on Node, Deno, Bun, Cloudflare worker...?
Mostly unsure what bundler + config and testing library to use.
Eg: Apparently it's possible to unit test on a browser?
Boilerplate repo:
https://github.com/MengLinMaker/npm-library-boilerplate
GitHub
Boilerplate for creating NPM library with CJS, ESM and DTS output. - MengLinMaker/npm-library-boilerplate