Skip to content

Commit

Permalink
Provide commonjs and esm bundles as entry points
Browse files Browse the repository at this point in the history
In this diff I replaced lib entry point with two bundles

main: ./dist/remarkable.cjs.js
module: ./dist/remarkable.esm.js

lib will be rewritten with esm.

Bundles has a few benefits
- faster startup time in node
- faster bundling
- internals are hidden and changing them will not affect users
  • Loading branch information
TrySound committed Jul 24, 2019
1 parent d627e16 commit 832abef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 0 additions & 3 deletions index.js

This file was deleted.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@
"index.js",
"lib"
],
"main": "index.js",
"bin": "./bin/remarkable.js",
"main": "./dist/remarkable.cjs.js",
"module": "./dist/remarkable.esm.js",
"engines": {
"node": ">= 0.10.0"
},
"scripts": {
"test": "make test",
"build": "make rollup",
"test": "make rollup && make test",
"test-ci": "nyc mocha -r esm -R spec --bail",
"coverage": "yarn add coveralls@2 && nyc report --reporter=text-lcov | coveralls"
},
Expand Down
22 changes: 22 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import path from 'path';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';

const name = 'Remarkable';
const external = id => !id.startsWith('.') && !path.isAbsolute(id);

export default [
{
input: ['./lib/index.js', './lib/linkify.js'],
output: { file: 'dist/cjs', format: 'cjs' },
external,
plugins: [
commonjs(),
]
},

{
input: ['./lib/index.js', './lib/linkify.js'],
output: { dir: 'dist/esm', format: 'esm' },
external,
plugins: [
commonjs(),
]
},

{
input: './lib/umd.js',
output: { file: 'dist/remarkable.js', format: 'umd', name },
Expand All @@ -13,6 +34,7 @@ export default [
commonjs(),
]
},

{
input: './lib/umd.js',
output: { file: 'dist/remarkable.min.js', format: 'umd', name },
Expand Down

0 comments on commit 832abef

Please sign in to comment.