This package shows how to get started with rollup (and babel) for writing
npm packages using ES6 modules. Producing npm packages by rollup allows users to choose
whether they use it using the traditional require
function understood by node.js, or using
the import
statement addedin ES6 which can result in smaller bundles through live-code
inclusion static analysis.
You can code in ES6 or TypeScript. Both will be transformed into ES5 by babel. If your packages are written in TypeScript, rollup automatically generates .d.ts files for you.
You can simply use this project as inspiration for how to configure your own, or clone it and edit the metadata files when starting your own project (i.e. README.md, package.json, and LICENSE).
First, go to the my-package folder, install the necessary packages.
cd my-package
npm install
Secondly, run build to generate es5 files into dist folder, and link it to npm locally.
npm run build
npm link
Then go to the example folder, link my-package to the project.
cd example
npm link my-package
Finally, you will notice that my-package is installed in node_modules successfully. Run code to test it.
node index.js