Building a tree shaking package using rollup.
- Set a
slideEffect: false
flag inpackage.json
"sideEffects": false,
- Make all export to input
- Setting output to
esm
export default {
input: ["src/*.ts"],
output: {
dir: pkg.module,
format: "esm",
},
plugins: [commonjs(), typescript(), resolve(), multiInput()],
};
- Build it!
import { foo } from "@chen86860/rollup-esm-template";
foo();
For that, the bar
function in @chen86860/rollup-esm-template
will not build into bundle by tree shaking.