Reputation: 2120
I’m building a TypeScript package to be published on NPM. I’ll be consuming this package in future web development projects likely using Vite. When I build a future website with this module, does it matter if it’s already bundled? Won’t Rollup (used by Vite to build the website) bundle the code regardless of whether the code on NPM is bundled (like in a lib.esm.js file)? Why not just use TSC (TypeScript Compiler) to compile TS to JS for NPM and then let the consuming project (whether Rollup or Webpack or Parcel) bundle it optimizing for the browser?
What am I missing that other NPM authors know?
Note, I’m authoring this package as strictly an ESM Module (type: module) so I’m not worrying about CJS.
Upvotes: 10
Views: 1365
Reputation: 8809
You’re right. You don’t need to bundle it. Just transpile each file individually from the source directory to the output directory and point your package.json’s main
to the transpiled entry point. Use Babel directly.
An example of this is react-markdown
.
Upvotes: 2