table of content
|
useful links
- how to publish a scoped package
- note that you'll need the
--access public
specification since scoped pkgs are private by default
- note that you'll need the
-
Entry point
Since we'll have to be transpiling our code for both
commonjs (.cjs)
andesm (.mjs)
(since those installing the package might opt for either), we needed to specify theentry points
for both modules.in the
package.json
file, the"module": "./dist/index.mjs"
key-val is to specify the path to theesm
module, assuming someone installing the package was using"type": "module"
in hispackage.json
.If he didn't specify and left the default
"type": "commonjs"
nodejs will be smart enough to use"main": "./dist/index.js"
in our package.json in place ofcommonjs
as his entry point to the packagetsup
will help us with this transpilation- Also checkout this article about tree-shaking with tsup
-
@types
the
"types": "./dist/index.d.ts"
specifies where our types will be kept assuming someone was usingTypeScript
and wanted to use some of our types.
- Read here on how to publish a
scoped
package
checkout this documentation from npmjs.com
-
npm login
- to login to your account through your cli
-
npm whoami
- to check who you are. It literally prints out your npm account username on the terminal
-
npm repo
- opens up the repository url that is set in the package.json of that project
-
npm publish
- publishes your package to npmjs.com
- use the
--access public
specification to specify that is public since scoped packages are private by default- there exist a
--access restricted
flag as well
- there exist a
-
npm access public
ornpm access restricted
- will update the access of an already published package
-
npm unpublish <test_pkg_name>@<version>
- use to unpublish a single package version
- you can unpublish all versions at once by running
npm unpublish <package_name> --force
-
npm link
- to create a global symlink (symbolic link) of the package your are building. use this to test locally.
- to use the symlink you created and simulate that package in another local project, navigate to the other project and run
npm link <test_pkg_name>
- to link the package you are testing in this other local project
- since it is a symlink, any changes you make in the original package will reflect in the places where you have linked the package
-
npm unlink
- to destroy the global symlink you created and unlink the package
- or you also go to where you used the symlink and run
npm unlink <test_pkg_name>
though this will not remove the global synlink
- to test your package locally, use the
npm link
andnpm unlink
commands explained in the section above (cool npm cli commands section)
- Use the
browser
property to indicate theentry point
of your app instead of themain
property if your package is mean to be used on theclient
. This is helpful to hint users that it might rely on primitives that aren't available in Node.js modules (link thewindow
object). Read more here