I believe they are doing code analysis, at least that's what the README for Rollup says:
> Rollup statically analyses your code, and your dependencies, and includes the bare minimum in your bundle.
> Rollup statically analyses your code, and your dependencies, and includes the bare minimum in your bundle.
var mod = {};
module.foo = function () { return 42; };
module.bar = function () { return -1; };
module[Math.random() > 0.5 ? "foo" : "bar"]();
How can `Rollup` determine that I need both functions here?Additionally, this method only works with named imports. So for example, you can have two files:
File a.js
export a = 5;
export b = 6;
export c = 7;
export d = 8;
export default {a, b, c, d};
File b.js import {a, b} from "./a.js";
console.log(a);
console.log(b);
c/d will never be included in the output file, nor will the default export. However, if you do: import a from "./a.js";
Then it won't optimize at all, because all of those objects are referenced in the default export.Note that it's possible I'm wrong as to the specific optimization method, but largely speaking this is how it should work.
https://github.com/rollup/rollup/blob/6fc8631ba1aad718885151...