How to publish a library to NPM with Rollup & TypeScript

Create & publish a library on NPM

Example rollup.config.js file:

import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import {terser} from "rollup-plugin-terser";
export default {
input: 'src/index.ts', // our source file
output: [
file: pkg.main,
format: 'cjs'
file: pkg.module,
format: 'es' // the preferred format
file: pkg.browser,
format: 'iife',
name: 'MyPackage' // the global which can be used in a browser
external: [
...Object.keys(pkg.dependencies || {})
plugins: [
typescript: require('typescript'),
terser() // minifies generated bundles

A few tips for publishing


Senior Software Engineer @LeanIX. Co-founder of Sedeo. Passion for software engineering and startups. Looking forward to build great things. 有難うございます。🚀

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store