Skip to content

Instantly share code, notes, and snippets.

@jamiebuilds
Created June 25, 2017 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiebuilds/2ef9dc85a84371fd000db0653d261bf0 to your computer and use it in GitHub Desktop.
Save jamiebuilds/2ef9dc85a84371fd000db0653d261bf0 to your computer and use it in GitHub Desktop.

Package source:

// math-pkg/src/index.js
export pow from './pow';
export square from './square';

// math-pkg/src/pow.js
export default function pow(x, n) {
  return Math.pow(x, n);
}

// math-pkg/src/square.js
import pow from './pow';
export default function square(x) {
  return pow(x, 2);
}

When bundled rollup-style with es modules:

// math-pkg/dist/bundle.js
export function pow(x, n) {
  return Math.pow(x, n);
}

export function square(x) {
  return pow(x, 2);
}

Usage of package in app:

// app/src/index.js
import {pow} from 'math-pkg';

pow(2, 3);

App bundled with rollup-style:

// app/dist/bundle.js
function pow(x, n) {
  return Math.pow(x, n);
}

function square(x) {
  return pow(x, 2);
}

pow(2, 3);

Dead code elimination:

// app/dist/bundle.min.js
function pow(x, n) {
  return Math.pow(x, n);
}

pow(2, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment