Common and best practices code are accumulated here in a NodeJS Lib for writting backend (API) services
In any TypeScript (or JavaScript) project, run:
npm i lakdak
Then in your code
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
}
}
- Parcel to build https://dev.to/ihaback/create-your-own-typescript-library-with-parceljs-3dh7
- pnpm for package management
- Vitest
pnpm i
pnpm dev
- Run
pnpm test
(watch mode) and change a test or source code to see HMR in action!
Support Type-Check, Compile and Minify for Production Support tree-shaking, each helper stays in its own file and can be imported separately Build to output both ES and UMD module.
- When introducing new class that need to expose, remember to export what you want to expose in
index.ts
- Change
package.json
version string
-
every push to repo will run CI check (
npm run ci
type check and unit test).- To skip CI check build, add
skipCI
to commit message
- To skip CI check build, add
-
create a tag (start with
v
andsemver
like v0.0.1) willnpm run build
and create a package on Github Packages https://github.com/vbee-holding/vbee-node-shared-lib/packages
Make this library intended to be consumed as an ES module. This setting ensures that Node.js treats .js files as ES modules by default.
We want to support both CommonJS and ES module consumers The build process outputs both module formats (already does this by specifying both main and module fields)
- CommonJS consumers to use the main entry point
- and ES module consumers to use the module entry point.
To avoid setup npm build and deploy, we can research to use deps like this: "@vbee-holding/node-shared-lib": "github:vbee-holding/vbee-node-shared-lib#v0.1.0" But this require the lib to be in public repo
- Run
pnpm release
- 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.3
)