- Write your library in
index.ts
-
npm run build
: Generate typesindex.d.ts
and libraryindex.js
via typescript tsc intodist/
folder - Create a story for your library like
trial1.stories.ts
, importing fromindex.js
to demo it on localhost:6006 -
npm pub
Package and publishdist/
folder
npm install countcores
import numcores from 'countcores';
console.log(numcores)
- package.json
- Add
"main": "dist/index.js",
- Published module entry point is here - Add
"files" : ["dist","README.md"],
- Only publishes files in dist and README.md to npm - Add
"types" : "dist/index.d.ts"
- Detect types entry point
- Add
- tsconfig.json
- Add
"outDir": "./dist",
- Output to dist folder - Add
"exclude": ["dist",...]
- Do not typecheck generated files - Add
"declaration": true,
- generate index.d.ts - Add
"typeRoots": ["@types", "node_modules/@types"],
- detect your own custom types folder@types
-
mkdir @types
and addglobal.d.ts
-
- Add
- Note: no need to install typedoc since the plugins with install the appropriate version
npm install typedoc-plugin-missing-exports
npm install --save-dev typedoc-umlclass
Add these script to package.json
"scripts": {
"build": "npm run clean && tsc",
"clean": "tsc --build --clean",
"cleandoc": "rm -r docs",
"doc": "typedoc --entryPointStrategy resolve .",
"test": "echo \"Error: no test specified\" && exit 1"
},
npm run build
npm run cleandoc
npm run doc
-
trial.stores.ts
is the story that uses our demo library.
npx storybook init
# select HTML
export NODE_OPTIONS=--openssl-legacy-provider
npm storybook start
#visit localhost:6006
Choose to deploy w/ github action as static page template
Modify path: '.'
==> path: './docs'
with:
# Upload entire repository
path: './docs'