Project template for building publicly available npm package.
Medium post: https://medium.com/@wickedmanok/build-and-publish-npm-packages-in-a-few-minutes-17494a30a51f
- Starter code in Typescript (for now).
- Tested on:
- npm 6.13.4
- node v10.19.0
-
Install cookiecutter
pip install cookiecutter
-
Cookie cut the template.
cookiecutter git@github.com:ardydedase/cookiecutter-npm-package.git
-
Enter the values accordingly. Pick a unique project name, it will be used as your npm package name. You can check if the package name is available in https://www.npmjs.com/.
-
Change the working directory to the generated folder, same name as the project slug.
cd <project_slug>
There is a sample reference package generated from our cookiecutter which you can refer to in here: https://github.com/ardydedase/reference-package.
-
Install dependencies
npm install
-
Run build. This will generate the compiled code with type definitions in the
dist
folder.npm run build
-
Formatting and linting.
npm run lint npm run format
-
Run tests
npm test
-
Build on top of the starter example in
src
folder is a simple function that returns a string.
Inside the generated folder, run the following commands:
-
If you don't have an npm account, create one on: https://www.npmjs.com/signup or run the command:
npm adduser
-
If you already have an account, login by running the following command:
npm login
-
When you're successfully logged-in. Publish the package:
npm publish
-
You should now be able to
npm install
your published package. There is an npm package called reference-package which is generated from this cookiecutter. There is a sample usage in example/index.js.
This cookiecutter template is originally based on this guide though slightly modified to my own preferences: https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c