npm login
npm publish
- to publish / update a packagenpm unpublish [package_name]
- to delete
The purpose of this boilerplate/framework is to quickly enable you to start developing NodeJS
and Browser
libraries.
It allows you to write code in the form of Typescript
that will be compiled in JavaScript es6
.
As a starting point, it's assuming that the library will require to send requests using the fetch
API in the browser and a custom library like node-fetch
in NodeJS.
The output will be placed inside dist
folder and it's represented by the following files.
browser.js
the output for browser (this file must be imported for a browser scenario)node.js
the output for NodeJS (this file must be imported for a NodeJS scenario)main.js
the common code between them*.d.ts
- declaration for browser,main and node js
!
The toolchain will not bundle the node_modules
libraries.
They are ommited using externals: [nodeExternals()]
property in webpack.config.js
,
As an example for this behavior node-fetch
was installed. You can run npm run build:prod
and inspect the code from index.js
.
!
Source Mapping
is enabled in webpack for development
environment with cheap-module-source-map
option by default.
You can modify it with your desired value
Webpack exposes two config objects nodeConfig
and browserConfig
. Both of them extend generalConfig
.
The configuration was inspired from their documentation.
! The library is exported as default
In a browser scenario where the library will be added using a script
tag, then the code will bind to global object window
using the name from browserConfig.output.library
. In this case MyLibrary
.
For testing, Jest
is configured and contains a dummy example.
npm run test
npm run test:watch
npm run test:cov
-
Build before publish and expose the files for a more appealing import - you can add this property inside
package.json
inscripts
object, if you need a hook before you publish your package. This command will be executed when you runnpm publish
, but before publishing the code."prepublishOnly": "webpack --mode=production && npm run expose",
-
Versioning - each time you run
npm publish
, be sure to update the version in"version": "1.0.0"
property insidepackage.json
. Otherwise you won't be able to deploy a new version. -
Ignoring files - use
.npmgignore
in the same way as.gitignore
, but for npm
!
No value for the properties main
, types
or files
was specified in package.json
, because here there is no main file, but rather two main files each one for a specific env.
The library must be imported
require("library/dist/node");