README
npm React module
Version: Basarat Ali
Process of creation
1. typescript npm module
npm init
Createpackage.json
npm i -D typescript
Install compilernpx tsc --init
Initializetsconfig.json
.
- Target es5
- module commonjs
- strict true
- esModuleInterop true
- declaration: true
- declarationMap: true
- sourceMap: true
- outDir: lib
- add include in src
touch src/index.ts
and add export some functiontweak
package.json
- Ensure unique package name
- main should point to "lib/index.js"
- add types pointing to lib
- add build script
tsc -p .
where the flag points to the project to compile
2. Enhance adding React
npm i react @types/react -D
Inpackage.json
add peerDependencies indicating that the project using this library should use a react with version at least 16.0.0Enable
jsx
toreact
intsconfig.json
mv src/index.ts src/index.tsx
and modify it to export a componentrun
npm run build
Derived from:
- Twitter | @basarat
- GitHub | Basarat Ali Syed
- YouTube | Basarat Ali
- Website | basarat.com