1.0.0 • Published 3 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 -ynpm i typescript -DInit TypeScript configurations
npx tsc --initInstal basic node types
npm install --save @types/nodeConfigurations
- Add
"declaration": trueto the compilerOptions of your tsconfig.json- This tells TypeScript to emit an
.d.tsdefinitions 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
diston repository - .npmignore -> Empty(overwrites .gitignore) file, to don't ignore
diston 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.tgzfile 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
3 years ago