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);