How to create and publish an npm package with TypeScript
· Category: TypeScript
Short answer
Initialize a project with package.json, configure tsconfig.json for declaration output, build with tsc, and publish using npm publish. Include type declarations so consumers get autocomplete. For module management patterns, see python pip install packages. For testing before release, see python testing with pytest.
Steps
- Initialize:
npm init -y - Install TypeScript:
npm install -D typescript - In
tsconfig.json, set"declaration": trueand"outDir": "dist" - Set
mainandtypesinpackage.json - Build and publish:
npm run build && npm publish
Tips
- Use
.npmignoreorfilesarray to limit published contents - Test your package locally with
npm link - For virtual environment isolation, see python virtual environments