How this was created:
- Make a
package.json
file
npm init
- Install
react
,react-dom
,typescript
,@types/react
,@types/react-dom
as devDependenvies
npm install --save-dev react react-dom typescript @types/react @types/react-dom
- add
react
andreact-dom
to peerDependencies
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
- Initialise a tsconfig file:
npx tsc --init
- Add the following to the tsconfig file:
"jsx": "react-jsx",
// optional?
"jsxImportSource": "react",
-
Create a
src
folder and a /components folder inside it -
Create a index.ts file inside the /components folder
-
Bundling using webpack:
- install webpack and webpack-cli as devDependencies
npm install --save-dev webpack webpack-cli ts-loader
- create a
webpack.config.js
file:
-
publishing to github npm packages:
- generate a PAT
- create your repo in gh
- add publish-config to package.json
- add a .npmrc file with the following, replace TOKEN with the PAT generated in step 1:
//npm.pkg.github.com/:_authToken=TOKEN
- Run
npm publish
, and you should see it in your github packages.
-
Installing the library:
- In your project, add a .npmrc file in the same level as your package.json file
@NAMESPACE:registry=https://npm.pkg.github.com //npm.pkg.github.com/:_authToken=TOKEN
- Install the package as per command in github packages!