{"id":18162669,"url":"https://github.com/nem0z/npm-package-guide-typescript","last_synced_at":"2026-04-11T20:38:58.971Z","repository":{"id":65240567,"uuid":"588751945","full_name":"nem0z/NPM-package-guide-typescript","owner":"nem0z","description":"A guide on creating an npm module using TypeScript, yarn, and ES modules, which can be utilized in both JavaScript and TypeScript projects that utilize either ES modules or CommonJS.","archived":false,"fork":false,"pushed_at":"2023-01-14T14:44:18.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-02T21:50:37.141Z","etag":null,"topics":["es-modules","npm","type"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nem0z.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-13T22:46:03.000Z","updated_at":"2023-01-14T14:47:35.000Z","dependencies_parsed_at":"2023-01-15T20:00:39.364Z","dependency_job_id":null,"html_url":"https://github.com/nem0z/NPM-package-guide-typescript","commit_stats":null,"previous_names":["nem0z/npm-module-tuto"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nem0z/NPM-package-guide-typescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem0z%2FNPM-package-guide-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem0z%2FNPM-package-guide-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem0z%2FNPM-package-guide-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem0z%2FNPM-package-guide-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nem0z","download_url":"https://codeload.github.com/nem0z/NPM-package-guide-typescript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nem0z%2FNPM-package-guide-typescript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273892841,"owners_count":25186561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es-modules","npm","type"],"created_at":"2024-11-02T10:04:54.200Z","updated_at":"2025-10-17T08:16:29.624Z","avatar_url":"https://github.com/nem0z.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# How to setup an NPM package ?\n\n- Build with TypeScript\n- Using ES Moudles (but also compatible with CommonJS)\n- That can be used in JavaScript AND TypeScript projects\n- That can be used in web or node environement\n\n/!\\ This package config will not fully  work in a `CommonJS` modules /!\\\n\n## 1/ Init NPM package\n\n```shell\n    $ yarn init\n```\nThen fill all fields (you can use default values for instance)\n\n## Install dependencies for `typescript` \n\n```shell\n    $ yarn add -D typescript tsc @types/node\n```\n\n## 3/ Add `tsconfig.json`\n\n```json\n    {\n        \"compilerOptions\": {\n            \"module\": \"node16\",             // Type of modules to use (also see moduleResolution)\n            \"target\": \"esnext\",             // Version of the transpilled JS\n            \"noImplicitAny\": true,\n            \"removeComments\": true,\n            \"preserveConstEnums\": true,\n            \"outDir\": \"./dist\",             // Folder for transpilled files (.js and .d.ts)\n            \"rootDir\": \"./src\",             // Folder with source files\n            \"declaration\": true,            // Create .d.ts files for 'types'\n            \"declarationMap\": true,         // \n            \"moduleResolution\": \"node16\",   // !important if you want to be able to use JS out with ES modules\n        },\n\n        \"include\": [\n            \"src/**/*\"\n        ],\n        \"exclude\": [\n            \"node_modules\"\n        ]\n    }\n```\n\n## 4/ Edit the `package.json`\n\n### Config package entries and type\n\n```json\n    ...\n    \"type\": \"module\",               // You want to use ES modules\n    \"types\": \"./dist/index.d.ts\",   // Entries for Ts types\n    \"main\": \"./dist/index.js\",      // Entries for Js usage\n    ...\n```\n\n### Add build script\n\n```json\n    \"scripts\": {\n        \"build\": \"tsc\"              // tsc will transpile the source files into .js and .d.ts files\n    },\n```\n\n## 5/ Add `.gitignore` and `.npmignore` files\n\n/!\\ It's importante to add the `.npmignore` event if you leave it empty as we will ignore the `dist/`folder in the github repo but we want to include it in the `NPM Package. In a way the `.npmignore` will overwrite the `.gitignore` for `npm`. /!\\\n\n### `.gitingore`\n\n```\n    node_modules/\n    dist/\n    yarn.lock\n```\n\n### `.npmignore`\n\n```\n    yarn.lock\n    src/\n```\n\nAdd the `src/`folder if you don't want to publish the source files on npm","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnem0z%2Fnpm-package-guide-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnem0z%2Fnpm-package-guide-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnem0z%2Fnpm-package-guide-typescript/lists"}