1.0.0 • Published 2 years ago
rc-npm-lib-ts-test v1.0.0
rc-npm-lib-ts-test
This is only a test to creating TS libs, and a little tutorial to how do it.
Obs. For more detailed, look at the references.
Requirements
- Nodejs
- Npm
Steps
npm init -y
npm i typescript -D
Init TypeScript configurations
npx tsc --init
Instal basic node types
npm install --save @types/node
Configurations
- Add
"declaration": true
to the compilerOptions of your tsconfig.json- This tells TypeScript to emit an
.d.ts
definitions file along with your compiled JavaScript.
- This tells TypeScript to emit an
- Add
"types": "index.d.ts"
to yourpackage.json
- When other people import your library, this tells the TypeScript compiler where to look for your library’s types.
"main": "dist/index.js", "types": "dist/index.d.ts",
- Config ts copimiler out put directory as
"outDir": "./dist",
in tsconfig.json file. - Important files .gitignore and .npmignore
- .gitignore -> Ignore
dist
on repository - .npmignore -> Empty(overwrites .gitignore) file, to don't ignore
dist
on NPM publish.
- .gitignore -> Ignore
- Prevent every publishing to run ts compiler before.
- Add
"prepublish": "tsc"
topackage.json
- Add
Run build
Tools
- Look details before publish
npm pack
> The pack command creates a.tgz
file exactly the way it would if you were going to publish the package to npm.
- Test Pack with
npm link
: See more in references.
References
1.0.0
2 years ago