Common and best practices code are accumulated here in a NodeJS Lib for writting backend (API) services
- Parcel to build https://dev.to/ihaback/create-your-own-typescript-library-with-parceljs-3dh7
- pnpm for package management
pnpm i
pnpm dev
- blazing fast unit test
- Run
pnpm test
(watch mode) and change a test or source code to see HMR in action!
Type-Check, Compile and Minify for Production
When introducing new class (helper), remember to export what you want to expose in
index.ts
pnpm build
- Support tree-shaking, each helper stays in its own file and can be imported separately
- Change
package.json
version - The output will be put to
/dist
(support both ESM-MJS and CommonJS-CJS-UMD) - commit the
.dist
folder to repo to publish it on Github - create new
versioned tag
for the release (E.g.:v0.2.1
)
In any TypeScript (or JavaScript) project, developer uses lakdak by add deps:
"lakdak": "github:gurucore/lakdak#v0.1.0"
import { FileHelper } from 'lakdak'
console.log(FileHelper())
If you cannot see the code suggestion (with comment), add this to tsconfig.json
{
"compilerOptions": {
"paths": {
"lakdak": ["./node_modules/lakdak/dist/types/index.d.ts"]
} // tells TypeScript: "When you see an import for 'lakdak', look exactly here for the types"
}
}
To benefit tree-shaking, add this to tsconfig.json
{
"compilerOptions": {
"module": "ES2022",
"moduleResolution": "bundler"
// This will give you better tree-shaking and modern module benefits
}
}