Your guide to what's next.
Creating a JavaScript library with webpack
Mar 9, 2020

Creating a JavaScript library with webpack

How to bundle a JavaScript library with webpack?

Webpack is a great tool for bundling JavaScript libraries.

The typical webpack.config.js used by a library looks something like this:

const path = require('path');

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'main.js',
        libraryTarget: 'commonjs'
    externals: { ... }

When bundling a library, is important to consider how it going to be loaded. In Node.js, libraries generally use module.exports in combination with require('...'). This is why libraryTarget is set to commonjs in the file above.

The externals configuration is used to specify the library's peer dependencies.

See also
Authenticating to an npm registry
How to authenticate to an npm registry?
Migrating from Google Cloud Source Repositories to GitHub
How to import a repository from Google Cloud Source to GitHub?
Publishing an npm package to GitHub Packages
How to publish an npm package to GitHub Packages?
Loading npm dependencies from multiple registries
How to add npm dependencies from multiple package registries?
Receiving email with Node.js
How to receive email in Node.js?
How to scp?
Using the scp command.