• 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):

    'maincjs.js:' 
      const printTest = require('./lib.js').test;
      const runTest = require('./run.js').run1;
    
      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")}(),module.exports={};
    
About

Avatar for opichals @opichals started