It looks like rollup with the commonjs plugin is quite clever. It does tree-shaking out-of-the box. The following outputs are outputs of rollup + commonjs + terser runs inside a browser (1.2MB minified).
Using import:
'main.js:'
import { test as printTest } from './lib.js';
import { run1 as runTest } from './run.js';
printTest();
runTest();
'/lib.js:'
function test() {
console.log('test');
};
function test1() {
console.log('test1');
};
module.exports = { test, test1 };
'/run.js:'
exports.run = function() {
console.log('run');
};
exports.run1 = function() {
console.log('run1');
};
'bundle.js:'
(function o(){console.log("test")})(),function(){console.log("run1")}();
Using require (not sure why it adds the dummy module.exports={}) at the end):
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
It looks like rollup with the commonjs plugin is quite clever. It does tree-shaking out-of-the box. The following outputs are outputs of rollup + commonjs + terser runs inside a browser (1.2MB minified).
Using
import
:Using
require
(not sure why it adds the dummy module.exports={}) at the end):