0.0.2 • Published 8 years ago
sample-es6-library v0.0.2
sample-es6-library
This shows how to distribute an ES6 library using Babel and rollup.
package.json#modulepoints to the raw ES6 code for modern browser consumptionpackage.json#mainpoints to legacy browser/node support and CommonJS modules.
Under the hood, it uses Babel and babel-runtime for legacy browser/Node.js support. babel-runtime (actually the transform-runtime plugin) polyfills only what the library uses and does so in a way that doesn't conflict with other versions of Babel. This is perfect for libraries.
We use rollup only to create the UMD bundle for JSFiddle consumption.
Installation
npm install sample-es6-libraryConsumption
// Web, webpack consumption, modern browsers only
import foo from 'sample-es6-library'
// Web, webpack consumption, legacy browser support
import foo from 'sample-es6-library/dist/legacy/index'
// Node.js
const foo = require('sample-es6-library')JSFiddle support: dist/legacy-umd/index.js is a UMD bundle that can be put behind a
CDN and loaded via a <script> tag. For
example,
here it is loaded
via jsdelivr.com.