1.0.4 • Published 4 years ago

npm-ts-package-template v1.0.4

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

A template for a npm package with typescript and jest

Inspired by this article

Initial steps

  1. make new folder: mrdir project-folder && cd project-folder
  2. create README.md file: echo "# My Awesome Project" >> README.md
  3. init git repository: git init
  4. commit README.md file: git add README.md && git commit -m "initial commit"
  5. create package.json: npm init -y

Create basic configuration files:

Install some essential packages

yarn add -D @types/jest \
            @typescript-eslint/eslint-plugin \
            @typescript-eslint/parser \
            eslint \
            eslint-config-prettier \
            eslint-plugin-prettier \
            eslint-plugin-simple-import-sort \
            jest \
            nodemon \
            prettier \
            ts-jest \
            typescript

Config for typescript

tsconfig.json

ESLint Config for typescript

tsconfig.eslint.json

Prettier config

.prettierrc

ESLint config

.eslintrc.js

Create .gitignore file

.gitignore

Create new scripts in the package.json

"scripts":

{
  "build": "tsc",
  "test": "jest",
  "test:coverage": "jest --coverage --verbose",
  "watch": "nodemon --watch src --exec yarn build",
  "lint": "eslint --fix --ignore-path .gitignore src && prettier --write --ignore-path .gitignore \"./**/*.json\"",
  "prepare": "yarn build",
  "prepublishOnly": "yarn lint && yarn test",
  "preversion": "yarn lint",
  "version": "git add -A",
  "postversion": "git push && git push --tags"
}