CLI tool to create npm package (Currently Work In Progress. Not published to NPM.)
Often I had to create NPM packages, and I found myself creating the same boilerplate code again and again. For very simple and tiny CommonJS modules, I had to configure
webpack differently than a library which I had to compile for
TypeScript configuration and devDependencies were different than that of
ES6. So, I figured better to create a CLI, which takes care of all that out of the box. Just answer few propmts, and the initial setup is done.
NOTE: You might not need it altogether, if you do not plan to use
TypeScript or unsupported NodeJs features, like
ES6 import. You can simply create your files in
It is needed when you are planning to expose the library as a
npm install -g @a6kme/create-npm-package
create-npm-package <YOUR_PACKAGE_NAME>command, and answer some prompts to create a folder with your package name.
npm login in the terminal window, you can directly run
npm publish --access public. It will test and build the package, and publish it on npm repository.
Currently, the CLI tool is highly opinionated about the choice of tools it uses. It uses
webpack for bundling,
jest for testing,
eslint for linting. It does the following for you
- Sets up the package directory with name of your package
package.json, with standard fields, like repository path, package name, and scripts for testing, linting etc.
- Initializes the git repository with
- Sets git remote origin with
eslintconfiguration file with appropriate parser
webpackbuilder configuration file
Check out my blog post about how to use this CLI at https://a6k.me/articles/how-to-create-and-publish-an-npm-package/