@johngeorgewright/ts-module
This is a template repository for creating a NPM package with TypeScript.
Setting up
- Change all references of
@johngeorgewright/ts-module
to your new package name - Also search for references to
@johngeorgewright
&ts-module
individually - Remove the
private
property frompackage.json
(if you want to publically publish your module) - Search for all references of
secrets.
in the.github
diectory and make sure you have the appropriate secrets registered in GitHub (Your Repo > Settings > Secrets) - Delete the .github/dependabot.yml file (unless you wish to use that instead of renovate)
- Ammend the LICENSE with your name
- If your packages are to be published publically, change the publish command in
release.config.js
toyarn npm publish --access public
Dependency management
By default, this project's dependencies is kept up-to-date with renovate. This project may also be set-up for dependabot too. To do so:
- Remove the
renovate.json
file mv .github/.dependabot.yml .github/dependabot.yml
ES & CommonJS Modules
This template is designed to help create libraries that produce both ES and CommonJS modules. It will create both the CommonJS and ESM distribution files, but to ensure that everything works correctly for parent projects, you must never import using local path protocols (IE ./my-module.js
). Always reference the fully qualified module that you have referenced in the your package.json
.
/* package.json */
{
"exports": {
".": {
"import": "./dist/es/index.js",
"require": "./dist/common/index.cjs"
},
"./module-2": {
"import": "./dist/es/module-2.js",
"require": "./dist/common/module-2.cjs"
}
},
"imports": {
"#module": {
"import": "./dist/es/module.js",
"require": "./dist/common/module.cjs"
}
}
}
// ./src/index.ts
import '@johngeorgewright/ts-module/module-2'
// ./src/module-2.ts
import '#private/module'
// ./src/module.ts